Skip to content

Add method hints for non-nullable return types and nullable arguments #2241

@Calinou

Description

@Calinou

See also #162 and #2242.

Describe the project you are working on

The Godot editor 🙂

Describe the problem or limitation you are having in your project

Currently, GDNative bindings must assume that all non-primitive return types (such as Node) may be null. This is problematic for safety-oriented languages such as Rust and Swift as it leads to uglier and unsafe code.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

  • Add method hints to ClassDB to signal that a return value will never be null. This hint should only be added to methods that return Object-derived types, not primitive types such as int or Vector2 as these are non-nullable by design. If this hint is not present, the method is assumed to have a nullable return type (for Object-derived types only).
  • Add a way to hint specific method arguments as being nullable. In other words, it means that the method will behave correctly if the specified arguments are null. If this hint is not present, the argument is assumed to be non-nullable.

This information can also be displayed in the generated class reference to improve documentation.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  • Non-null return type hinting could be implemented as a ClassDB method flag such as METHOD_FLAG_RETURN_NON_NULL.
  • Nullable argument hinting could be implemented using argument metadata feature (GodotTypeInfo::Metadata).

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, as this is core engine functionality.

Is there a reason why this should be core and not an add-on in the asset library?

This functionality is part of the engine itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions