HaxeFoundation / HaxeFoundation/haxe

[null-safety] if vs. ?.

Open
#12,561 15 comments 0 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

```haxe
class C {
public function new() {}

public function isTrue() {
return true;
}
}

final c:Null = new C();

function main() {
if (c != null && c.isTrue()) {}
if (c?.isTrue()) {}
}
```

`Null safety: Cannot use nullable value as condition in "if".`

This might be a bit of a special case, but I'd expect the second version to be equivalent to the first one. Probably needs fixing at the typing stage already because if it's generating `if (c == null ? null : c.isTrue())` then I understand why null-safety would complain.

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.