HaxeFoundation / HaxeFoundation/haxe

[nullsafety] constant object literals with nullable fields

Open
#7,854 0 comments 0 reactions 1 assignee Claimed by @RealyUniqueName View on GitHub
enhancement feature-null-safety
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Null safety is smart enough to detect that `a` can never be null here despite being declared as `Null`, so this compiles:

```haxe
var a:Null> = [];
a.push(0);
```

Consequently, this should also compile:

```haxe
@:nullSafety
class Main {
static function main() {
var s:Struct = {
values: []
}
s.values.push(0); // Null safety: Cannot access "push" of a nullable value.
}
}

typedef Struct = {
?values:Array
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.