Commit e6e94f7
[flow_analysis] Don't promote on invalid type
Flow analysis didn't handle invalid type so non-null promotion would occur on declaration and initialization on erroneous code, leading to warnings about null-aware that is likely valid. For instance
f(Unresolved o) { // Error: Unresolved is unresolved
int? i = o.property;
i?.isEven; // Warning about unnecessary null-aware access
if (i != null) { // Warning about unnecessary null comparison
i.isEven;
}
}
To handle this fully we need to track invalid nullability (if that is even feasible) but for now we change the default to avoid non-null promotion in such cases.
This *does* change the kind cascading errors/warnings that we produce. For instance
f(Unresolved o) { // Error: Unresolved is unresolved
int? i = o.nonNullProperty;
i.isEven; // Error for access on int?
}
but since it probably more likely for code to *not* depend on non-null promotion, this should be less noise for the user.
Change-Id: Ia2bc3505a43b52e5151b93a7fee24e95246b4bbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443320
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>1 parent e3d4534 commit e6e94f7
File tree
12 files changed
+156
-2
lines changed- pkg
- analyzer
- lib/src/dart/resolver
- test
- id_tests
- src/diagnostics
- front_end
- lib/src/type_inference
- test/id_tests
12 files changed
+156
-2
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4034 | 4034 | | |
4035 | 4035 | | |
4036 | 4036 | | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
4037 | 4042 | | |
4038 | 4043 | | |
4039 | 4044 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12639 | 12639 | | |
12640 | 12640 | | |
12641 | 12641 | | |
| 12642 | + | |
| 12643 | + | |
| 12644 | + | |
| 12645 | + | |
| 12646 | + | |
| 12647 | + | |
| 12648 | + | |
| 12649 | + | |
| 12650 | + | |
| 12651 | + | |
| 12652 | + | |
| 12653 | + | |
| 12654 | + | |
| 12655 | + | |
| 12656 | + | |
| 12657 | + | |
| 12658 | + | |
| 12659 | + | |
| 12660 | + | |
| 12661 | + | |
| 12662 | + | |
| 12663 | + | |
12642 | 12664 | | |
12643 | 12665 | | |
12644 | 12666 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3298 | 3298 | | |
3299 | 3299 | | |
3300 | 3300 | | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
3301 | 3306 | | |
3302 | 3307 | | |
3303 | 3308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1285 | 1285 | | |
1286 | 1286 | | |
1287 | 1287 | | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1288 | 1293 | | |
1289 | 1294 | | |
1290 | 1295 | | |
| |||
1316 | 1321 | | |
1317 | 1322 | | |
1318 | 1323 | | |
1319 | | - | |
| 1324 | + | |
1320 | 1325 | | |
1321 | 1326 | | |
1322 | 1327 | | |
| |||
1355 | 1360 | | |
1356 | 1361 | | |
1357 | 1362 | | |
1358 | | - | |
1359 | 1363 | | |
1360 | 1364 | | |
1361 | 1365 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
667 | 672 | | |
668 | 673 | | |
669 | 674 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
329 | 360 | | |
330 | 361 | | |
331 | 362 | | |
| |||
Lines changed: 52 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
89 | 115 | | |
90 | 116 | | |
91 | 117 | | |
| |||
97 | 123 | | |
98 | 124 | | |
99 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
100 | 152 | | |
101 | 153 | | |
102 | 154 | | |
| |||
0 commit comments