-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desugar switchable matches with guards in async methods
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`.
- Loading branch information
Showing
5 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//> using options -Xasync | ||
|
||
import scala.tools.partest.async.OptionAwait._ | ||
import org.junit.Assert._ | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
assertEquals(Some(22), sw1(11)) | ||
assertEquals(Some(3), sw1(3)) | ||
|
||
assertEquals(Some(22), sw2(11)) | ||
assertEquals(Some(3), sw2(3)) | ||
|
||
assertEquals(Some(22), sw3(11)) | ||
assertEquals(Some(44), sw3(22)) | ||
assertEquals(Some(3), sw3(3)) | ||
|
||
assertEquals(Some("22"), swS("11")) | ||
assertEquals(Some("3"), swS("3")) | ||
} | ||
|
||
private def sw1(i: Int) = optionally { | ||
i match { | ||
case 11 if value(Some(430)) > 42 => 22 | ||
case p => p | ||
} | ||
} | ||
|
||
private def sw2(i: Int) = optionally { | ||
i match { | ||
case 11 => if (value(Some(430)) > 42) 22 else i | ||
case p => p | ||
} | ||
} | ||
|
||
private def sw3(i: Int) = optionally { | ||
i match { | ||
case 11 => if (value(Some(430)) > 42) 22 else i | ||
case 22 | 33 => 44 | ||
case p => p | ||
} | ||
} | ||
|
||
private def swS(s: String) = optionally { | ||
s match { | ||
case "11" if value(Some(430)) > 42 => "22" | ||
case p => p | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters