-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
macro new - was: Configurable @:structInit initializer #5292
Comments
Can I bump this, dear @Simn 😄 |
to be conformant with @:build, maybe it should be `@:structInit(my.MacroClass.doSomething()) which we would append the object as last argument, but then that's no longer a structInit thing since you can return any AST that would not create a Point, so maybe the semantic is more about
And this would pass either arguments of "new" or object initializer if structInit |
I like it. But for expression to be typed the macro should return something that's typable as var p : Point = 123.123; // type has to become a Point So the How about keeping I have no strong opinion on syntax. Symmetry with |
Bump after awesome "eval" talk :D |
Simon said he likes the idea of |
I can't think of a technical reason not to support |
Isn't it similar to what can be achieved with |
@szczepanpp not really unless |
@vizanto maybe I'm not noticing something crucial about this proposal but as I understand it you get exactly the same usage with abstracts right now. I'm not saying I'm against, just pointing out that we have this feature already. Btw. you show example of a It's greatly simplified, just to show initialization from an
|
@szczepanpp thanks, you're right that @:structInit probably doesn't have to allow array syntax. My latest proposal (which may not be clear when reading from top to bottom) is to allow This allows classes tagged with |
Hmm, @szczepanpp if I change your example slightly: I can't find the |
That's a thing I wonder about myself. Didn't need to do anything with it yet, so I wasn't really exploring what it means and how to actually use it. I guess our macro expert knows the answer (@back2dos of course). :) |
@Simn please don't forget |
I would like to add |
Is it |
You're right, although I would speculate that a class that has a macro constructor is also quite likely to have macro methods, in which case it's going to be an |
Pushing this back to 4.1 because I'm concerned about conditional compilation problems. It's also not a breaking change. |
4.1 will be epic, someday |
Can't wait to be in 2022 |
As of Haxe 3.3.0-rc1, classes annotated with
@:structInit
will have their constructor called with arguments from the struct literal expression.I'm proposing a small addition to this mechanism to allow a macro to modify this expression.
Instead of always mapping it to a constructor call, pass it to a macro call.By allowing constructors to be macros:This would allow us to implement several things in libraries:
var p : Point = {};
withvar p = Point.empty;
)var p : Point = {x: "1", y: "2"}; => macro calling Std.parseInt
Because
@:structInit
would reverse the macro call "responsibility", this gives us new macro powers without having to abuse@:build
or similar at the instantiation point.If the compiler would pass array literals to
macro structInit
as well, this would allow implementing set literals using array syntax:The text was updated successfully, but these errors were encountered: