Commit 5d78579
[analyzer] Fix dead code reporting for null-aware accesses.
A null-aware access can result in dead code if the target has static
type `Null`. The analyzer wasn't properly accounting for this,
resulting in some confusing ranges reported for the DEAD_CODE warning.
This change causes the following expressions to report dead code for
the code ranges indiced by `^`:
Null myNullVar = null;
myNullVar?[index];
// ^^^^^^ DEAD_CODE
myNullVar?[index] = value;
// ^^^^^^^^^^^^^^ DEAD_CODE
myNullVar?.method();
// ^^^^^^^^ DEAD_CODE
myNullVar?.property;
// ^^^^^^^^ DEAD_CODE
myNullVar?.property = value;
// ^^^^^^^^^^^^^^^^ DEAD_CODE
Note that the bug was confined solely to the logic that reports the
DEAD_CODE warning; there is no change to the reachability inferred by
flow analysis (and hence, this is a non-breaking change).
Fixes #60364.
Bug: #60364
Change-Id: I068826282fba6b9057e9c27d1d9310c65714e203
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416723
Auto-Submit: Paul Berry <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>1 parent 5d1f487 commit 5d78579
File tree
3 files changed
+68
-1
lines changed- pkg
- analyzer
- lib/src/generated
- test/src/diagnostics
3 files changed
+68
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1239 | 1239 | | |
1240 | 1240 | | |
1241 | 1241 | | |
| 1242 | + | |
1242 | 1243 | | |
1243 | 1244 | | |
1244 | 1245 | | |
| |||
1404 | 1405 | | |
1405 | 1406 | | |
1406 | 1407 | | |
| 1408 | + | |
1407 | 1409 | | |
1408 | 1410 | | |
1409 | 1411 | | |
| |||
1457 | 1459 | | |
1458 | 1460 | | |
1459 | 1461 | | |
| 1462 | + | |
1460 | 1463 | | |
1461 | 1464 | | |
1462 | 1465 | | |
| |||
2838 | 2841 | | |
2839 | 2842 | | |
2840 | 2843 | | |
| 2844 | + | |
2841 | 2845 | | |
2842 | 2846 | | |
2843 | 2847 | | |
| |||
3055 | 3059 | | |
3056 | 3060 | | |
3057 | 3061 | | |
| 3062 | + | |
3058 | 3063 | | |
3059 | 3064 | | |
3060 | 3065 | | |
| |||
3945 | 3950 | | |
3946 | 3951 | | |
3947 | 3952 | | |
| 3953 | + | |
3948 | 3954 | | |
3949 | 3955 | | |
3950 | 3956 | | |
| |||
4009 | 4015 | | |
4010 | 4016 | | |
4011 | 4017 | | |
| 4018 | + | |
4012 | 4019 | | |
4013 | 4020 | | |
4014 | 4021 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
205 | 265 | | |
206 | 266 | | |
207 | 267 | | |
| |||
0 commit comments