Closed
Description
In the following example:
// test.scala
object Foo {
def foo(i: Int) = i match {
case 2 => println(2)
case 1 => println(1)
}
}
foo
gets transformed into a switch. But if the @switch
annotation is added on i
, this kills the transformation. Running ./bin/dotc -Xprint:patternMatch test.scala
yields the following without a switch annotation:
result of test.scala after TreeTransform:{patternMatcher, explicitOuter, explicitSelf, crossCast, splitter}:
package <empty> {
final lazy module val Foo: Foo$ = new Foo$()
@dotty.annotation.internal.SourceFile("test.scala") final module class Foo$()
extends
Object() {
def foo(i: Int): Unit = {
case val selector11: Int = i
selector11.toInt match {
case 2 =>
println(2)
case 1 =>
println(1)
case _ => throw new MatchError(selector11)
}
}
}
}
And, with the annotation:
result of test.scala after TreeTransform:{patternMatcher, explicitOuter, explicitSelf, crossCast, splitter}:
package <empty> {
final lazy module val Foo: Foo$ = new Foo$()
@dotty.annotation.internal.SourceFile("test.scala") final module class Foo$()
extends
Object() {
def foo(i: Int): Unit = {
case val selector11: Int @switch = i: Int @switch
{
def case11(): Unit = {
def case21(): Unit = {
def matchFail11(): Unit = throw new MatchError(selector11)
if 1.==(selector11) then {
val x31: Int(1) = selector11.asInstanceOf[Int(1)]
{
{
println(1)
}
}
} else matchFail11()
}
if 2.==(selector11) then {
val x21: Int(2) = selector11.asInstanceOf[Int(2)]
{
{
println(2)
}
}
} else case21()
}
case11()
}
}
}
}