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

Track the ExtensionTypeElement associated with constant DartObjects. #55693

Open
mattrberry opened this issue May 11, 2024 · 1 comment
Open
Labels
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-enhancement A request for a change that isn't a bug

Comments

@mattrberry
Copy link
Contributor

mattrberry commented May 11, 2024

I'd like to propose a feature that would allow users of the analyzer to work back to the extension type for a DartObject, similar to what was done with VariableElement.

This will give lints and code generators a little bit of visibility into how an object is constructed and its type.

The particular limitation I'm seeing now is when an extension type is defined over a private type. For a reduced and contrived example, take

class _Foo {
  const _Foo();
}
extension type const Foo._(_Foo _) implements _Foo {
  const Foo() : this._(const _Foo());
}

In this case, the lint or code generator might want to do something with the static type Foo. Today, the analyzer believes that the type of const Foo() is a _Foo which is true at runtime, but doesn't allow much further. A lint or generator might want to understand what a Foo is, even if it won't exist at runtime. The lint or generator sometimes can't even tell that the object is an extension type, let alone what the extension is.

For an example with Mockito, see

@GenerateNiceMocks([MockSpec<Foo>()])

which produces the error

Invalid @GenerateMocks annotation: Mockito cannot mock a private type: '_Foo'.

(FWIW this might be a bad example, but it's one of the cases that breaks with my real use-case for the contrived example above. Maybe Mockito itself could be updated to handle this case, I'm not sure.) I have been looking at supporting this for Angular, though, where an app might want to provide an instance of Foo, but the framework can't figure out how to produce code for that because all it sees is _Foo.

I'll conclude here rather than let this get too rambly :) Please let me know if there are cases I'm not accounting for regarding why this couldn't or shouldn't be implemented! If there's just a bandwidth issue, I'm happy to look into it myself because it's potentially limiting some other high impact work. Thanks!

@mraleph mraleph added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 11, 2024
@srawlins srawlins added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels May 13, 2024
@bwilkerson
Copy link
Member

@scheglov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants