jakemac53 / macro_prototype

A very basic prototype of macros using build_runner
BSD 3-Clause "New" or "Revised" License
73 stars 7 forks source link

Allow a class/mixin to implicitly apply a macro wherever it is mixed in or extended? #31

Open jakemac53 opened 3 years ago

jakemac53 commented 3 years ago

I am not sure this is a good idea, but filing it to have a central area for discussion.

The general idea is to have a mechanism available whereby mixing in or extending a particular class would auto apply some macros to the class that mixed it in or extended it.

This would eliminate the need for annotations in some cases, and enable frameworks to "hide" the macro applications from their users. Consider for instance:

class MyWidgetState extends State<MyWidget> with AutoListener {}

Instead of:

@autoListen
class MyWidgetState extends State<MyWidget> {}

Potentially frameworks could even add macro applications to their base classes (ie: State or Widget) in this example.

Pros

Cons

munificent commented 3 years ago

Related: Allow a macro applied to a function to do something at every invocation site of the function. That could be nice for debug-only code so that the call can be completely eliminated, including the evaluation of its arguments.

jakemac53 commented 3 years ago

Related: Allow a macro applied to a function to do something at every invocation site of the function. That could be nice for debug-only code so that the call can be completely eliminated, including the evaluation of its arguments.

I think that probably becomes https://github.com/jakemac53/macro_prototype/issues/29 - or at least this could cover that use case.