Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure isEmpty's type isn't constant folded
Also test the same is true for unapply.
- Loading branch information
Showing
7 changed files
with
132 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[[syntax trees at end of patmat]] // newSource1.scala | ||
package <empty> { | ||
object A extends scala.AnyRef { | ||
def <init>(): A.type = { | ||
A.super.<init>(); | ||
() | ||
}; | ||
def unapplySeq(a: Int): Wrap = new Wrap(a) | ||
}; | ||
class T extends scala.AnyRef { | ||
def <init>(): T = { | ||
T.super.<init>(); | ||
() | ||
}; | ||
def t: Any = { | ||
case <synthetic> val x1: Int(2) = 2; | ||
case5(){ | ||
<synthetic> val o7: Wrap = A.unapplySeq(x1); | ||
if (o7.isEmpty.unary_!) | ||
{ | ||
val xs: Seq[Int] = o7.get.toSeq; | ||
matchEnd4(xs) | ||
} | ||
else | ||
case6() | ||
}; | ||
case6(){ | ||
matchEnd4("other") | ||
}; | ||
matchEnd4(x: Any){ | ||
x | ||
} | ||
} | ||
} | ||
} | ||
|
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,31 @@ | ||
import scala.tools.partest._ | ||
|
||
object Test extends DirectTest { | ||
def depCode = | ||
"""class Wrap(private val a: Int) extends AnyVal { | ||
| def isEmpty: false = { println("confirm seq isEmpty method doesn't get elided"); false } | ||
| def get = this | ||
| def lengthCompare(len: Int) = Integer.compare(1, len) | ||
| def apply(i: Int) = if (i == 0) a else Nil(i) | ||
| def drop(n: Int): scala.Seq[Int] = if (n == 0) toSeq else Nil | ||
| def toSeq: scala.Seq[Int] = List(a) | ||
|} | ||
""".stripMargin | ||
|
||
override def code = | ||
"""object A { | ||
| def unapplySeq(a: Int) = new Wrap(a) | ||
|} | ||
|class T { | ||
| def t: Any = 2 match { | ||
| case A(xs @ _*) => xs | ||
| case _ => "other" | ||
| } | ||
|} | ||
""".stripMargin | ||
|
||
def show(): Unit = Console.withErr(System.out) { | ||
compileString(newCompiler("-usejavacp"))(depCode) | ||
compileString(newCompiler("-usejavacp", "-cp", testOutput.path, "-Vprint:patmat"))(code) | ||
} | ||
} |
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,25 @@ | ||
[[syntax trees at end of patmat]] // newSource1.scala | ||
package <empty> { | ||
class T extends scala.AnyRef { | ||
def <init>(): T = { | ||
T.super.<init>(); | ||
() | ||
}; | ||
def t: Any = { | ||
case <synthetic> val x1: Int(2) = 2; | ||
case5(){ | ||
if (A.unapply(x1)) | ||
matchEnd4("ok") | ||
else | ||
case6() | ||
}; | ||
case6(){ | ||
matchEnd4("other") | ||
}; | ||
matchEnd4(x: Any){ | ||
x | ||
} | ||
} | ||
} | ||
} | ||
|
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,23 @@ | ||
import scala.tools.partest._ | ||
|
||
object Test extends DirectTest { | ||
def depCode = | ||
"""object A { | ||
| def unapply(a: Int): true = true | ||
|} | ||
""".stripMargin | ||
|
||
override def code = | ||
"""class T { | ||
| def t: Any = 2 match { | ||
| case A() => "ok" | ||
| case _ => "other" | ||
| } | ||
|} | ||
""".stripMargin | ||
|
||
def show(): Unit = Console.withErr(System.out) { | ||
compileString(newCompiler("-usejavacp"))(depCode) | ||
compileString(newCompiler("-usejavacp", "-cp", testOutput.path, "-Vprint:patmat"))(code) | ||
} | ||
} |
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