diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-02-24 14:42:33 +0100 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-02-24 14:45:00 +0100 |
commit | 7def1a90a01f5ac1e6e4e6b0c0cd58f131874a2f (patch) | |
tree | 3568d312ba462cb0b61992cd7d657dc829b48843 | |
parent | 718a8974f4de14e52006ff152a0f4679fe5318c9 (diff) | |
download | scala-7def1a90a01f5ac1e6e4e6b0c0cd58f131874a2f.tar.gz scala-7def1a90a01f5ac1e6e4e6b0c0cd58f131874a2f.tar.bz2 scala-7def1a90a01f5ac1e6e4e6b0c0cd58f131874a2f.zip |
SI-8330: Mismatch in stack heights
The SI-8233 / 9506d52 missed one case when we need to DROP a null from
a stack: when unboxed Unit is an expected type. If we forgot to do that
in a context where two branches were involved we could end up with
unbalanced stack sizes.
Let's fix that omission and a test covering that specific case to the
original test for SI-8233.
Fixes SI-8330.
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 3 | ||||
-rw-r--r-- | test/files/run/t8233-bcode.scala | 15 | ||||
-rw-r--r-- | test/files/run/t8233.scala | 15 |
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 } } |