HaxeFlixel / HaxeFlixel/flixel

[ENHANCEMENT] Implement null safety

Open
#3,267 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Code Style / Cleanup Improvement Structure
Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

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.

Tasks:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Haxe null safety documentation and review pull request #3440, which is the only completed task listed. No files or tests are named; the stated long-term outcome is incremental null-safety coverage throughout HaxeFlixel, with nullable values documented and handled safely.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.