Skip to content

[ENHANCEMENT] Implement null safety #3267

Open
@EliteMasterEric

Description

@EliteMasterEric

Null safety is an optional feature of the Haxe compiler which enforces compile-time checking of nullable values.

By implementing null safety throughout HaxeFlixel, we can greatly reduce the frequency of crashes and other errors. This can be done using the @:nullSafety annotation at the top of each class, and can be done incrementally until every class in the library is compliant.

This would not break existing code which has null safety enabled, but it would:

  • Improve documentation by informing users which variables are Null-able (such as FlxG.sound.music).
  • Reduce the incidence of certain crashes within the engine by guaranteeing they are caught and handled.
  • Improve the compatibility with other code where null safety is enabled.

As an example of the last case, I have started to enable null safety in Funkin', and have had to create blocks of code where null safety is not enabled in several places, simply because Flixel itself regularly neglects to use Null<T> for nullable values (again, trying to set FlxG.sound.music = null makes the compiler complain until you specifically exclude that line).

One major obstacle to implementing null safety is that null safety is not necessarily finalized (see this issue or any of these issues). Overall though, I would like to see it become a long-term goal of the engine, especially since it can be done in a non-breaking manner in most cases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions