Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10775 from lrytz/t12990
Desugar switchable matches with guards in async methods
- 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