HaxeFoundation / HaxeFoundation/haxe

null safety and map.exists

Open
#7,866 5 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 isn't aware of map.exists which leads to warnings:

Main.hx
```haxe
class Main {
static function main() {
var m = [1 => 2, 5 => 3];

for (c in 0...10) {
if (m.exists(c))
{
m[c]++;
}
else
{
m[c] = 0;
}

trace(m[c]);
}
}
}
```

build.hxml
```hxml
-main Main
--interp
--macro nullSafety("Main", Strict)
```

Result
```
Main.hx:8: characters 5-11 : Null safety: Cannot assign nullable value here.
Main.hx:8: characters 5-11 : Null safety: Cannot perform binary operation on nullable value.
Main.hx:15: characters 10-14 : Null safety: Cannot pass nullable value to not-nullable argument "v" of function "trace".
```
Displayed 10 times (is the loop unrolled?)

Also we might want to make trace take a Null since `trace(null);` works fine.

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.