Created
October 2, 2018 16:31
-
-
Save sjrd/16e9cb6c7d7b9a2093cf1521f93f2209 to your computer and use it in GitHub Desktop.
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
// source code | |
def test3(x: Int, y: Int): Int = (x: @switch) match { | |
case 6 if y > 5 => 1 | |
//case 6 => 2 | |
case 12 => 3 | |
case 14 => 4 | |
case _ => 5 | |
} | |
// dotty emits this if `case 6 =>` is present | |
def test3(x: Int, y: Int): Int = (x: @switch) match { | |
case 6 => | |
if (y > 5) 1 | |
else 2 | |
case 12 => 3 | |
case 14 => 4 | |
case _ => 5 | |
} | |
// scalac emits this | |
def test3(x: Int, y: Int): Int = (x: @switch) match { | |
case 6 => | |
if (y > 5) 1 | |
else default() | |
case 12 => 3 | |
case 14 => 4 | |
case _ => | |
default() { | |
5 | |
} | |
} | |
// what dotty could emit to match scalac's capabilities | |
def test3(x: Int, y: Int): Int = { | |
matchResult[Int]: { | |
(x: @switch) match { | |
case 6 => | |
if (y > 5) return[matchResult] 1 | |
else () | |
case 12 => return[matchResult] 3 | |
case 14 => return[matchResult] 4 | |
case _ => () | |
} | |
5 | |
} | |
} | |
// what the tree-rendered of the Plan looks like | |
// which is what we should analyze to produce the previous snippet | |
def test3(x: Int, y: Int): Int = { | |
val x1 = x | |
matchResult[Int]: { | |
if (x1 == 6) { | |
if (y > 5) { | |
return[matchResult] 1 | |
} | |
} | |
if (x1 == 12) { | |
... | |
} | |
return[matchResult] 5 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment