diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala index 962c47f44321..e79193647081 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala @@ -736,7 +736,13 @@ abstract class TypeFlowAnalysis { val succs = point.successors filter relevantBBs succs foreach { p => assert((p.predecessors filter isOnPerimeter).isEmpty) - val updated = lattice.lub(List(output, in(p)), p.exceptionHandlerStart) + val existing = in(p) + // TODO move the following assertion to typeFlowLattice.lub2 for wider applicability (ie MethodTFA in addition to MTFAGrowable). + assert(existing == lattice.bottom || + p.exceptionHandlerStart || + (output.stack.length == existing.stack.length), + "Trying to merge non-bottom type-stacks with different stack heights. For a possible cause see SI-6157.") + val updated = lattice.lub(List(output, existing), p.exceptionHandlerStart) if(updated != in(p)) { in(p) = updated enqueue(p) diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index dd7676a3719d..22f0a9ca7c98 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -981,8 +981,8 @@ abstract class Inliners extends SubComponent { return DontInlineHere("too low score (heuristics)") } - if(inc.hasHandlers && (stackLength != 0)) { - // TODO pending return DontInlineHere("callee contains exception handlers / finally clause, and is invoked with non-empty operand stack") // SI-6157 + if(inc.hasHandlers && (stackLength > inc.minimumStack)) { + return DontInlineHere("callee contains exception handlers / finally clause, and is invoked with non-empty operand stack") // SI-6157 } if(isKnownToInlineSafely) { return InlineableAtThisCaller } diff --git a/test/files/pos/t6157.flags b/test/files/pos/t6157.flags new file mode 100644 index 000000000000..0ebca3e7afeb --- /dev/null +++ b/test/files/pos/t6157.flags @@ -0,0 +1 @@ + -optimize diff --git a/test/files/pos/t6157.scala b/test/files/pos/t6157.scala new file mode 100644 index 000000000000..7463989b14c1 --- /dev/null +++ b/test/files/pos/t6157.scala @@ -0,0 +1,25 @@ +// SI-6157 - Compiler crash on inlined function and -optimize option + +object Test { + def main(args: Array[String]) { + Console.println( + ErrorHandler.defaultIfIOException("String")("String") + ) + } +} + +import java.io.IOException + +object ErrorHandler { + + @inline + def defaultIfIOException[T](default: => T)(closure: => T): T = { + try { + closure + } catch { + case e: IOException => + default + } + } +} + diff --git a/test/files/run/private-inline.scala b/test/files/run/private-inline.scala index a45300b0267f..a62007779c5e 100644 --- a/test/files/run/private-inline.scala +++ b/test/files/run/private-inline.scala @@ -30,7 +30,7 @@ final class A { } object Test { - def methodClasses = List("f1a", "f1b", "f2a", "f2b") map ("A$$anonfun$" + _ + "$1") + def methodClasses = List("f1a", "f2a") map ("A$$anonfun$" + _ + "$1") def main(args: Array[String]): Unit = { val a = new A