Commit 31e7f7c
authored
Relax flow typing checks on Flexible Types (#24278)
These changes allow flow-typing to view flexible types as non-nullable
at relevant places.
```scala
//> using options -Yexplicit-nulls
def main() =
var result: String | Null = null
result = "".trim()
result.trim()
```
Without this PR, the access of trim on result will give an error. This
pattern is used in community build projects like sconfig.
After this change, calling .nn on a flexible type **directly** will
still not give a warning, as intended.
However, calling .nn on a variable that is previously flow typed to be a
flexible type will now give a warning as a side effect of this change.
We believe that the benefits of this change outweigh the drawback.File tree
2 files changed
+10
-1
lines changed- compiler/src/dotty/tools/dotc/core
- tests/explicit-nulls/pos
2 files changed
+10
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments