HaxeFoundation / HaxeFoundation/haxe

Assertion function/exception does not satisfy null safety

Open
#11,296 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

**Minimal reproduction of this issue:** https://try.haxe.org/#Cb6cD3c8

**Expected behavior:** Since `Assert.isNotNull()` throws an exception, which is caught and handled by the try/catch block, `takesNotNull()` will never be reached if `input` is null, thus null safety should be satisfied. However, the compiler provides the following:

```
[ERROR] Test.hx:24: characters 19-24

24 | takesNotNull(input);
| ^^^^^
| Null safety: Cannot pass nullable value to not-nullable argument "input" of function "takesNotNull".
```

**Application/Use case:** The example above is from when I was implementing a set of unit tests for my application, and I annotated them with `@:nullSafety` with the expectation that `Assert.isNotNull` would be recognized as a null safety sentinel.

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.