summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2014-02-24 16:37:03 +0100
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2014-02-24 16:37:03 +0100
commit7c709e122f7471353749525cff15602783fb348c (patch)
tree3568d312ba462cb0b61992cd7d657dc829b48843
parent718a8974f4de14e52006ff152a0f4679fe5318c9 (diff)
parent7def1a90a01f5ac1e6e4e6b0c0cd58f131874a2f (diff)
downloadscala-7c709e122f7471353749525cff15602783fb348c.tar.gz
scala-7c709e122f7471353749525cff15602783fb348c.tar.bz2
scala-7c709e122f7471353749525cff15602783fb348c.zip
Merge pull request #3580 from gkossakowski/issue/SI-8330
SI-8330: Mismatch in stack heights
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala3
-rw-r--r--test/files/run/t8233-bcode.scala15
-rw-r--r--test/files/run/t8233.scala15
3 files changed, 30 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 81fbbfcabf..1cea4bedda 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1011,9 +1011,10 @@ abstract class GenICode extends SubComponent {
// emit conversion
if (generatedType != expectedType) {
tree match {
- case Literal(Constant(null)) if generatedType == NullReference =>
+ case Literal(Constant(null)) if generatedType == NullReference && expectedType != UNIT =>
// literal null on the stack (as opposed to a boxed null, see SI-8233),
// we can bypass `adapt` which would otherwise emitt a redundant [DROP, CONSTANT(null)]
+ // except one case: when expected type is UNIT (unboxed) where we need to emit just a DROP
case _ =>
adapt(generatedType, expectedType, resCtx, tree.pos)
}
diff --git a/test/files/run/t8233-bcode.scala b/test/files/run/t8233-bcode.scala
index fae1c2b702..72d013e553 100644
--- a/test/files/run/t8233-bcode.scala
+++ b/test/files/run/t8233-bcode.scala
@@ -11,8 +11,21 @@ object Test {
bar(a)
}
- def main(args: Array[String]) = {
+ /** Check SI-8330 for details */
+ def expectedUnitInABranch(b: Boolean): Boolean = {
+ if (b) {
+ val x = 12
+ ()
+ } else {
+ // here expected type is (unboxed) Unit
+ null
+ }
+ true
+ }
+
+ def main(args: Array[String]): Unit = {
try { nullReference } catch { case _: NoSuchElementException => }
literal
+ expectedUnitInABranch(true)
}
}
diff --git a/test/files/run/t8233.scala b/test/files/run/t8233.scala
index fae1c2b702..97a98a2e21 100644
--- a/test/files/run/t8233.scala
+++ b/test/files/run/t8233.scala
@@ -11,8 +11,21 @@ object Test {
bar(a)
}
- def main(args: Array[String]) = {
+ /** Check SI-8330 for details */
+ def expectedUnitInABranch(b: Boolean): Boolean = {
+ if (b) {
+ val x = 12
+ ()
+ } else {
+ // here expected type is (unboxed) Unit
+ null
+ }
+ true
+ }
+
+ def main(args: Array[String]): Unit = {
try { nullReference } catch { case _: NoSuchElementException => }
literal
+ expectedUnitInABranch(true) // Was: VerifyError under GenICode
}
}