HaxeFoundation / HaxeFoundation/haxe

Null Safety hole with array access

Open
#11,585 4 comments 4 reactions 0 assignees View on GitHub
feature-null-safety
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Array access will return `null` on index not found, yet return type is `T`, not `Null`:

```haxe
@:nullSafety(Strict)
class Test {
static function main() {
var s:String = foo(42);
trace(s == null); // true
// s = null; // Null safety: Cannot assign nullable value here.
}

static function foo(i:Int) {
var arr:Array = [];
return arr[i];
}
}
```
https://try.haxe.org/#1DeFA9FA

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the null-safety example from the issue at the linked try.haxe.org entry. Trace how array access is typed under @:nullSafety(Strict), and identify the relevant compiler tests or type-checking entry point. Done means an out-of-range Array access is represented consistently with its possible null result and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.