-
Notifications
You must be signed in to change notification settings - Fork 7
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
Statement/Expression/Element macros #29
Comments
Thinking some more about this I was wondering if reusing the annotation syntax is going to limit macros applicability in these situations, since currently macros always have to have an element to annotate. Expressions is just one application, creating top-level definitions / declarations based off of a |
The thinking so far has been to add library level macros (which would likely annotate the library directive). You can also annotate imports I think? so that could be one option (annotate the import of the macro itself?). If we do statement/expression/element level macros they very likely would look a bit different and not be annotation based (probably look like a function call). |
+1 for function-looking macros. I would really like the ability to do: final value = @macro(params); |
In particular, I was thinking that function-like macros would be a good solution for #18 / flutter_hooks and #37 For #37, the idea is that we'd change: final dependency = Provider(...);
final provider = Provider<MyClass>((ref) {
final value = ref.watch(dependency);
return MyClass();
},
dependencies: { dependency },
); into: final dependency = Provider(...);
final provider = Provider<MyClass>((ref) {
final value = @watch(dependency);
return MyClass();
}); and the macro would take care of adding the entry to "dependencies". In this case, the macro parameter wouldn't be the |
Mostly a placeholder issue for now, we need to spec this feature out.
The general idea is to allow macros inside of constructor bodies. These macros would be able to inline any code they wish at their invocation site, effectively replacing a call to the macro with arbitrary code.
Use cases might include:
assert
that actually inlines nothing in release builds.These macros would likely run in a new 4th macro phase, and would have full reflective access to the program, but would not be able to add any new declarations to the program, only inline some code at the site where they are invoked.
The text was updated successfully, but these errors were encountered: