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

How to reference extension methods in macro generated code? #55672

Open
jakemac53 opened this issue May 8, 2024 · 0 comments
Open

How to reference extension methods in macro generated code? #55672

jakemac53 opened this issue May 8, 2024 · 0 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). feature-macros Implementation of the macros feature library-macros The experimental dart:_macros library

Comments

@jakemac53
Copy link
Contributor

Extension methods don't map well to the Identifier abstraction as it exists today. In general I think to emit code which calls an extension method you would have to wrap the receiver in the extension (MyExtension(receiver)) and then call the extension method on that (maybe by name, not sure an identifier of the extension method would work).

In general this wrapping is necessary to eliminate ambiguity from generated augmentations, but it would be ideal if we could automatically do the wrapping for you. So for instance, you would just use the identifier for an extension method in the same way you would use an identifier to an instance method, and we would perform the wrapping for you:

ExpressionCode.fromParts([someInstanceIdentifier, '.', someExtensionMethodIdentifier, '()'])

Would become:

TheExtension(theInstance).theExtensionMethod();
@jakemac53 jakemac53 added feature-macros Implementation of the macros feature library-macros The experimental dart:_macros library labels May 8, 2024
@devoncarew devoncarew added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). feature-macros Implementation of the macros feature library-macros The experimental dart:_macros library
Projects
None yet
Development

No branches or pull requests

2 participants