Skip to content

Commit f181a9b

Browse files
committed
Fix for scala#2817. Review by mharrah.
1 parent 28c75a8 commit f181a9b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/compiler/scala/tools/nsc/Interpreter.scala

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ class Interpreter(val settings: Settings, out: PrintWriter)
103103
}
104104
}
105105

106+
/** whether to bind the lastException variable */
107+
private var bindLastException = true
108+
109+
/** Temporarily stop binding lastException */
110+
def withoutBindingLastException[T](operation: => T): T = {
111+
val wasBinding = bindLastException
112+
ultimately(bindLastException = wasBinding) {
113+
bindLastException = false
114+
operation
115+
}
116+
}
117+
106118
/** interpreter settings */
107119
lazy val isettings = new InterpreterSettings(this)
108120

@@ -477,10 +489,7 @@ class Interpreter(val settings: Settings, out: PrintWriter)
477489
val binderObject = loadByName(binderName)
478490
val setterMethod = methodByName(binderObject, "set")
479491

480-
// this roundabout approach is to ensure the value is boxed
481-
var argsHolder: Array[Any] = null
482-
argsHolder = List(value).toArray
483-
setterMethod.invoke(null, argsHolder.asInstanceOf[Array[AnyRef]]: _*)
492+
setterMethod.invoke(null, value.asInstanceOf[AnyRef])
484493
interpret("val %s = %s.value".format(name, binderName))
485494
}
486495

@@ -791,9 +800,13 @@ class Interpreter(val settings: Settings, out: PrintWriter)
791800
val wrapperExceptions: List[Class[_ <: Throwable]] =
792801
List(classOf[InvocationTargetException], classOf[ExceptionInInitializerError])
793802

794-
def onErr: Catcher[(String, Boolean)] = { case t: Throwable =>
795-
quietBind("lastException", "java.lang.Throwable", t)
796-
(stringFrom(t.printStackTrace(_)), false)
803+
/** We turn off the binding to accomodate ticket #2817 */
804+
def onErr: Catcher[(String, Boolean)] = {
805+
case t: Throwable if bindLastException =>
806+
withoutBindingLastException {
807+
quietBind("lastException", "java.lang.Throwable", t)
808+
(stringFrom(t.printStackTrace(_)), false)
809+
}
797810
}
798811

799812
catching(onErr) {

0 commit comments

Comments
 (0)