Skip to content

Conversation

dmlloyd
Copy link
Member

@dmlloyd dmlloyd commented Apr 7, 2025

Fixes #250

@dmlloyd dmlloyd added the 2.x Issue applies to Gizmo 2.x label Apr 7, 2025
@dmlloyd dmlloyd moved this to In Progress in WG - Gizmo 2 Apr 7, 2025
ifc.withType(String.class);
ifc.final_();
ifc.withInitializer(b0 -> {
b0.yield(b0.withString(Constant.of("Hello")).concat(Constant.of(" world")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yield() call here is not entirely intuitive, but I'm not sure what we can do about that. Maybe make withInitializer() take Function<BlockCreator, Expr> instead of Consumer<BlockCreator>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not specific to this case... any block which has an output type (including switch expressions, ?:, etc.) works this way. I agree it's not super intuitive and it can be easy to mess it up, but I don't see a good way of changing it in a uniform way without breaking a lot of things (or else changing all Consumer to Function and requiring users to return a void constant or something).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a separate discussion on that, at any rate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure.

Copy link
Contributor

@Ladicek Ladicek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM baring the typos.

@dmlloyd dmlloyd merged commit 39ae862 into quarkusio:main Apr 8, 2025
2 checks passed
@dmlloyd dmlloyd deleted the field-init branch April 8, 2025 12:28
@github-project-automation github-project-automation bot moved this from In Progress to Done in WG - Gizmo 2 Apr 8, 2025
Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit late but still - this is awesome!

There are too many withInitial() overloads for my taste but that's not a big deal.

*
* @param initial the initial value
*/
default void withInitial(Class<?> initial) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, do you expect many Class<?> fields? 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue applies to Gizmo 2.x
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Gizmo2: Instance field initializers
3 participants