From 814ecad8a0f4830ce97112e00e4823a2b5c047e0 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 10 Mar 2014 11:26:07 +0100 Subject: SI-8363 Disable -Ydelambdafy:method in constructor position As @magarciaEPFL has done in his experimental optimizer [1], we can avoid running into limitations of lambdalift (either `VerifyError`s, ala SI-6666, or compiler crashes, such as this bug), by using the old style of "inline" lambda translation when in a super- or self- construtor call. We might be able to get these working later on, but for now we shouldn't block adoption of `-Ydelamndafy:method` for this corner case. [1] https://github.com/magarciaEPFL/scala/blob/GenRefactored99sZ/src/compiler/scala/tools/nsc/transform/UnCurry.scala#L227 --- src/compiler/scala/tools/nsc/transform/UnCurry.scala | 4 +++- test/files/pos/t8363.flags | 1 + test/files/pos/t8363.scala | 7 +++++++ test/pending/pos/t8363b.scala | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t8363.flags create mode 100644 test/files/pos/t8363.scala create mode 100644 test/pending/pos/t8363b.scala diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 8a7d30235f..d77c6b54a9 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -221,7 +221,9 @@ abstract class UnCurry extends InfoTransform def mkMethod(owner: Symbol, name: TermName, additionalFlags: FlagSet = NoFlags): DefDef = gen.mkMethodFromFunction(localTyper)(fun, owner, name, additionalFlags) - if (inlineFunctionExpansion) { + val canUseDelamdafyMethod = (inConstructorFlag == 0) // Avoiding synthesizing code prone to SI-6666, SI-8363 by using old-style lambda translation + + if (inlineFunctionExpansion || !canUseDelamdafyMethod) { val parents = addSerializable(abstractFunctionForFunctionType(fun.tpe)) val anonClass = fun.symbol.owner newAnonymousFunctionClass(fun.pos, inConstructorFlag) addAnnotation SerialVersionUIDAnnotation anonClass setInfo ClassInfoType(parents, newScope, anonClass) diff --git a/test/files/pos/t8363.flags b/test/files/pos/t8363.flags new file mode 100644 index 0000000000..48b438ddf8 --- /dev/null +++ b/test/files/pos/t8363.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/test/files/pos/t8363.scala b/test/files/pos/t8363.scala new file mode 100644 index 0000000000..639faf4120 --- /dev/null +++ b/test/files/pos/t8363.scala @@ -0,0 +1,7 @@ +class C(a: Any) +class Test { + def foo: Any = { + def form = 0 + class C1 extends C(() => form) + } +} diff --git a/test/pending/pos/t8363b.scala b/test/pending/pos/t8363b.scala new file mode 100644 index 0000000000..393e2a0237 --- /dev/null +++ b/test/pending/pos/t8363b.scala @@ -0,0 +1,7 @@ +class C(a: Any) +class Test { + def foo: Any = { + def form = 0 + class C1 extends C({def x = form; ()}) + } +} -- cgit v1.2.3