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

[backport] desugar switchable matches with guards in async methods #10779

Merged
merged 1 commit into from May 13, 2024

Conversation

lrytz
Copy link
Member

@lrytz lrytz commented May 8, 2024

Backport of #10775

The async transformation supports Match trees that are left in place for the backend to emit a switch in bytecode.

Guards are desugared into a jump to the default case

case 22 if p => 5
case _       => 6

becomes

case 22 => if (p) 5 else default()
case _  => default: { 6 }

This pattern is unexpected for the async transform and leads to invalid bytecode if the guard p has an await call.

The fix is to desugar switchable matches with guards in patmat if the enclosing method has the AsyncAttachment.

The async transformation supports `Match` trees that are left in place
for the backend to emit a switch in bytecode.

Guards are desugared into a jump to the default case

    case 22 if p => 5
    case _       => 6

becomes

    case 22 => if (p) 5 else default()
    case _  => default: { 6 }

This pattern is unexpected for the async transform and leads to
invalid bytecode if the guard `p` has an await call.

The fix is to desugar switchable matches with guards in patmat
if the enclosing method has the `AsyncAttachment`.
@scala-jenkins scala-jenkins added this to the 2.12.20 milestone May 8, 2024
@lrytz lrytz merged commit 735198f into scala:2.12.x May 13, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants