Commit fe6f87f
[analyzer] Fix dead code reporting in property access and is/as.
The way dead code detection works in the analyzer is that at various
ad hoc times during the process of resolution (typically before
visiting an expression or statement), the `ResolverVisitor` calls
`checkUnreachableNode`, which asks flow analysis whether the current
point in execution is reachable, and if it isn't, arranges for an
unreachable code warning to be produced.
This wasn't working for property extractions, type casts, and type
tests because there's no subexpression whose execution follows the
subexpression that returns `Never`, so `checkUnreachableNode` wasn't
getting called.
The fix is simple; just add some calls to `checkUnreachableNode` to
cover the RHS of a property access, type cast, or type test.
Note that property accesses in the analyzer can be represented either
as `PrefixedIdentifier` or `PropertyAccess`, so the property access
fix had to be done in two places (and accordingly there are two tests
for it).
Fixes #60247.
Bug: #60247
Change-Id: I49e739784f629b77443ce6d31e67809f48de75be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413521
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
Auto-Submit: Paul Berry <[email protected]>1 parent 29c24db commit fe6f87f
File tree
5 files changed
+51
-0
lines changed- pkg/analyzer
- lib/src
- dart/resolver
- generated
- test/src
- dart/resolution
- diagnostics
5 files changed
+51
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1822 | 1822 | | |
1823 | 1823 | | |
1824 | 1824 | | |
| 1825 | + | |
1825 | 1826 | | |
1826 | 1827 | | |
1827 | 1828 | | |
| |||
3070 | 3071 | | |
3071 | 3072 | | |
3072 | 3073 | | |
| 3074 | + | |
3073 | 3075 | | |
3074 | 3076 | | |
3075 | 3077 | | |
| |||
3455 | 3457 | | |
3456 | 3458 | | |
3457 | 3459 | | |
| 3460 | + | |
3458 | 3461 | | |
3459 | 3462 | | |
3460 | 3463 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
| 1047 | + | |
1047 | 1048 | | |
1048 | 1049 | | |
1049 | 1050 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
| |||
157 | 167 | | |
158 | 168 | | |
159 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
160 | 181 | | |
161 | 182 | | |
162 | 183 | | |
| |||
194 | 215 | | |
195 | 216 | | |
196 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
197 | 238 | | |
198 | 239 | | |
199 | 240 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
889 | 889 | | |
890 | 890 | | |
891 | 891 | | |
| 892 | + | |
892 | 893 | | |
893 | 894 | | |
894 | 895 | | |
| |||
916 | 917 | | |
917 | 918 | | |
918 | 919 | | |
| 920 | + | |
919 | 921 | | |
920 | 922 | | |
921 | 923 | | |
| |||
987 | 989 | | |
988 | 990 | | |
989 | 991 | | |
| 992 | + | |
990 | 993 | | |
991 | 994 | | |
992 | 995 | | |
| |||
1142 | 1145 | | |
1143 | 1146 | | |
1144 | 1147 | | |
| 1148 | + | |
1145 | 1149 | | |
1146 | 1150 | | |
1147 | 1151 | | |
| |||
1171 | 1175 | | |
1172 | 1176 | | |
1173 | 1177 | | |
| 1178 | + | |
1174 | 1179 | | |
1175 | 1180 | | |
1176 | 1181 | | |
| |||
0 commit comments