Files
sdk/pkg/analyzer/test
Paul Berry eb5983869c [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 <scheglov@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2025-02-08 08:15:19 -08:00
..
2025-01-10 07:54:39 -08:00