From 1ee6352a79d0b9001f4f1249708e7c6350b241ae Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 7 Oct 2014 15:09:28 +1000 Subject: SI-8888 Avoid ClassFormatError under -Ydelambdafy:method The pattern matcher phase (conceivably, among others) can generate code that binds local `Ident`s symbolically, rather than according to the lexical scope. This means that a lambda can capture more than one local of the same name. In the enclosed test case, this ends up creating the following tree after delambdafy [[syntax trees at end of delambdafy]] // delambday-patmat-path-dep.scala matchEnd4({ case val x1: Object = (x2: Object); case5(){ if (x1.$isInstanceOf[C]()) { val x2#19598: C = (x1.$asInstanceOf[C](): C); matchEnd4({ { (new resume$1(x2#19598, x2#19639): runtime.AbstractFunction0) }; scala.runtime.BoxedUnit.UNIT }) } else case6() }; ... }) ... class resume$1 extends AbstractFunction0 { var x2: C = null; var x2: C = null; ... } After this commit, the var members of `resume$1` are given fresh names, rather than directly using the name of the captured var: var x2$3: C = null; var x2$4: C = null; --- src/compiler/scala/tools/nsc/transform/Delambdafy.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala index 12e7b23f48..835d338ab3 100644 --- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala +++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala @@ -260,7 +260,7 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre val captureProxies2 = new LinkedHashMap[Symbol, TermSymbol] captures foreach {capture => - val sym = lambdaClass.newVariable(capture.name.toTermName, capture.pos, SYNTHETIC) + val sym = lambdaClass.newVariable(unit.freshTermName(capture.name.toString + "$"), capture.pos, SYNTHETIC) sym setInfo capture.info captureProxies2 += ((capture, sym)) } -- cgit v1.2.3