Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyzer: InheritanceManager3.getInheritedConcreteMap2 throws, given an extension type #53638

Closed
srawlins opened this issue Sep 28, 2023 · 4 comments
Assignees
Labels
analyzer-api Issues that impact the public API of the analyzer package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@srawlins
Copy link
Member

Ran across this while working extension type support into dartdoc. I think it is valid to pass an extension type-derived InterfaceElement to InheritanceManager3.getInheritedConcreteMap2, but that method then throws this:

Bad state: No element

dart:core-patch/array.dart 56:5                                           _Array.last
package:analyzer/src/dart/element/inheritance_manager3.dart 178:39        InheritanceManager3.getInheritedConcreteMap2
pkg/analyzer/test/src/dart/element/inheritance_manager3_test.dart 448:27  InheritanceManager3Test_ExtensionType.test_getInheritedConcreteMap_x
===== asynchronous gap ===========================
package:test_reflective_loader/test_reflective_loader.dart 281:21         _runTest.<fn>
===== asynchronous gap ===========================
package:test_api/src/backend/declarer.dart 215:9                          Declarer.test.<fn>.<fn>
===== asynchronous gap ===========================
package:test_api/src/backend/declarer.dart 213:7                          Declarer.test.<fn>
===== asynchronous gap ===========================
package:test_api/src/backend/invoker.dart 258:9                           Invoker._waitForOutstandingCallbacks.<fn>

because InheritanceManager3._getInterfaceExtensionType returns Interface._(..., superImplemented: const []).

CC @scheglov

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) analyzer-api Issues that impact the public API of the analyzer package labels Sep 28, 2023
@pq pq added the P2 A bug or feature request we're likely to work on label Sep 29, 2023
@scheglov
Copy link
Contributor

scheglov commented Oct 9, 2023

The documentation says about superclasses and mixins.

  /// Return signatures of all concrete members that the given [element] inherits
  /// from the superclasses and mixins.
  Map<Name, ExecutableElement> getInheritedConcreteMap2(
      InterfaceElement element) {
    var interface = getInterface(element);
    return interface.superImplemented.last;
  }

And extension types don't have them.

What is the use case for invoking it for extension types?

@srawlins
Copy link
Member Author

srawlins commented Oct 9, 2023

Given this code:

extension type ET(int it) implements num {}

I can call .abs() on an expression of type ET. But ET does not declare abs. If it doesn't "inherit" it either, what word do we use?

Even if I should not be calling getInheritedConcreteMap2 with an extension type, it should not crash.

@scheglov
Copy link
Contributor

scheglov commented Oct 9, 2023

Inherited methods are not necessary concrete.
So, getInheritedConcreteMap2() is wrong API for this.
I think we should use getInheritedMap2() instead.

https://dart-review.googlesource.com/c/sdk/+/329782 adds a check to prevent the crash, and expands the test to print inheritedMap.

@scheglov scheglov self-assigned this Oct 9, 2023
@srawlins
Copy link
Member Author

srawlins commented Oct 9, 2023

Excellent thanks for the tip!

@scheglov scheglov closed this as completed Oct 9, 2023
copybara-service bot pushed a commit that referenced this issue Oct 9, 2023
…invocation.

Bug: #53638
Change-Id: I49bc912a56fab85f206a997a84261b964a27d370
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329782
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-api Issues that impact the public API of the analyzer package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants