Commit eb59838
[analyzer] Fix PartElementImpl.enclosingUnit.
`PartElementImpl.enclosingElement3` has static type `Element?`, but in
practice it is always of type `CompilationUnitElementImpl`, due to
this code from `CompilationUnitElementImpl.parts=`:
set parts(List<PartElementImpl> parts) {
for (var part in parts) {
part.enclosingElement3 = this;
var uri = part.uri;
if (uri is DirectiveUriWithUnitImpl) {
uri.unit.enclosingElement3 = this;
}
}
_parts = parts;
}
Therefore, `PartElementImpl.enclosingUnit` can just cast
`enclosingElement3` to the proper type and return it.
This behavior was untested, so I've added a test in
`part_test.dart`. Without the fix, the test throws a `TypeError`.
Change-Id: I3e6f186826aa92cda9c3887c85c5eddc1fea7f31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408641
Reviewed-by: Konstantin Shcheglov <[email protected]>
Auto-Submit: Paul Berry <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>1 parent 4227821 commit eb59838
File tree
2 files changed
+17
-4
lines changed- pkg/analyzer
- lib/src/dart/element
- test/src/dart/resolution
2 files changed
+17
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9653 | 9653 | | |
9654 | 9654 | | |
9655 | 9655 | | |
9656 | | - | |
9657 | | - | |
9658 | | - | |
9659 | | - | |
| 9656 | + | |
| 9657 | + | |
9660 | 9658 | | |
9661 | 9659 | | |
9662 | 9660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
19 | 34 | | |
20 | 35 | | |
21 | 36 | | |
| |||
0 commit comments