diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Delambdafy.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 7 | ||||
-rw-r--r-- | test/files/neg/t6260-named.scala | 2 |
3 files changed, 13 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala index b28a4a507d..d81a5d5755 100644 --- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala +++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala @@ -232,6 +232,10 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre val parents = addSerializable(abstractFunctionErasedType) val funOwner = originalFunction.symbol.owner + // TODO harmonize the naming of delamdafy anon-fun classes with those spun up by Uncurry + // - make `anonClass.isAnonymousClass` true. + // - use `newAnonymousClassSymbol` or push the required variations into a similar factory method + // - reinstate the assertion in `Erasure.resolveAnonymousBridgeClash` val suffix = "$lambda$" + ( if (funOwner.isPrimaryConstructor) "" else "$" + funOwner.name @@ -283,8 +287,10 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre else s"$sym: ${sym.tpe} in ${sym.owner}" bridgeMethod foreach (bm => + // TODO SI-6260 maybe just create the apply method with the signature (Object => Object) in all cases + // rather than the method+bridge pair. if (bm.symbol.tpe =:= applyMethodDef.symbol.tpe) - erasure.expandNameOfMethodThatClashesBridge(applyMethodDef.symbol) + erasure.resolveAnonymousBridgeClash(applyMethodDef.symbol, bm.symbol) ) val body = members ++ List(constr, applyMethodDef) ++ bridgeMethod diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index e2ffafb850..60c1553ef3 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -484,7 +484,7 @@ abstract class Erasure extends AddInterfaces !sigContainsValueClass || (checkBridgeOverrides(member, other, bridge) match { case Nil => true - case es if member.owner.isAnonymousClass => expandNameOfMethodThatClashesBridge(member); true + case es if member.owner.isAnonymousClass => resolveAnonymousBridgeClash(member, bridge); true case es => for ((pos, msg) <- es) unit.error(pos, msg); false }) ) @@ -1137,9 +1137,12 @@ abstract class Erasure extends AddInterfaces } } - final def expandNameOfMethodThatClashesBridge(sym: Symbol) { + final def resolveAnonymousBridgeClash(sym: Symbol, bridge: Symbol) { + // TODO reinstate this after Delambdafy generates anonymous classes that meet this requirement. + // require(sym.owner.isAnonymousClass, sym.owner) log(s"Expanding name of ${sym.debugLocationString} as it clashes with bridge. Renaming deemed safe because the owner is anonymous.") sym.expandName(sym.owner) + bridge.resetFlag(BRIDGE) } private class TypeRefAttachment(val tpe: TypeRef) diff --git a/test/files/neg/t6260-named.scala b/test/files/neg/t6260-named.scala index 7ce13476eb..7cd9ce8473 100644 --- a/test/files/neg/t6260-named.scala +++ b/test/files/neg/t6260-named.scala @@ -7,7 +7,7 @@ object Test { (x: C[Any]) => {println(s"f($x)"); x} // okay new T[C[Any]] { def apply(a: C[Any]) = a } // okay - // we can't rename the specific apply methid to avoid the clash + // we can't rename the specific apply method to avoid the clash object O extends Function1[C[Any], C[Any]] { def apply(a: C[Any]) = a } |