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

Fix 'yield outside of switch expression' #1502

Merged
merged 1 commit into from Feb 6, 2024

Conversation

alsin
Copy link

@alsin alsin commented Jan 25, 2024

When using Immutables with Java versions supporting switch expressions (and the new yield keyword) and if one decides to define an immutable interface with say getYield() method:

@Value.Immutable
public interface SomeInterface {
    int getYield();
}

the value processor generates an immutable class implementation which won't compile since the internal generated Builder class would have the following copying method:

    @CanIgnoreReturnValue 
    public final Builder from(SomeInterface instance) {
      Objects.requireNonNull(instance, "instance");
      yield(instance.getYield()); <-- here the compiler will fail with 'Yield outside of switch expression'
      return this;
    }

It's enough to prepend the method call with this. and the compilation passes.

@elucash elucash merged commit a490b41 into immutables:master Feb 6, 2024
16 checks passed
@elucash
Copy link
Member

elucash commented Feb 6, 2024

Thank you for the PR, I wonder if there are other places affected.

@alsin
Copy link
Author

alsin commented Feb 20, 2024

Thank you for the PR, I wonder if there are other places affected.

You're welcome! Could be, I just came across this bug on this particular place. Had to fix it temporarily by changing the setter style (using set*).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants