diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index aaae703d06..a2eddd34bd 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -755,7 +755,7 @@ abstract class Erasure extends AddInterfaces while (opc.hasNext) { val member = opc.overriding val other = opc.overridden - //Console.println("bridge? " + member + ":" + member.tpe + member.locationString + " to " + other + ":" + other.tpe + other.locationString)//DEBUG + //println("bridge? " + member + ":" + member.tpe + member.locationString + " to " + other + ":" + other.tpe + other.locationString)//DEBUG if (atPhase(currentRun.explicitouterPhase)(!member.isDeferred)) { val otpe = erasure(owner, other.tpe) val bridgeNeeded = atPhase(phase.next) ( @@ -790,8 +790,19 @@ abstract class Erasure extends AddInterfaces member.tpe match { case MethodType(List(), ConstantType(c)) => Literal(c) case _ => - (((Select(This(owner), member): Tree) /: bridge.paramss) + val bridgingCall = (((Select(This(owner), member): Tree) /: bridge.paramss) ((fun, vparams) => Apply(fun, vparams map Ident))) + // type checking ensures we can safely call `other`, but unless `member.tpe <:< other.tpe`, calling `member` is not guaranteed to succeed + // in general, there's nothing we can do about this, except for an unapply: when this subtype test fails, return None without calling `member` + if ( member.isSynthetic // TODO: should we do this for user-defined unapplies as well? + && ((member.name == nme.unapply) || (member.name == nme.unapplySeq)) + // && (bridge.paramss.nonEmpty && bridge.paramss.head.nonEmpty && bridge.paramss.head.tail.isEmpty) // does the first argument list has exactly one argument -- for user-defined unapplies we can't be sure + && !(atPhase(phase.next)(member.tpe <:< other.tpe))) { // no static guarantees (TODO: is the subtype test ever true?) + import CODE._ + val typeTest = gen.mkIsInstanceOf(REF(bridge.paramss.head.head), member.tpe.params.head.tpe, any = true, wrapInApply = true) // any = true since we're before erasure (?), wrapInapply is true since we're after uncurry + // println("unapp type test: "+ typeTest) + IF (typeTest) THEN bridgingCall ELSE REF(NoneModule) + } else bridgingCall }); debuglog("generating bridge from " + other + "(" + Flags.flagsToString(bridge.flags) + ")" + ":" + otpe + other.locationString + " to " + member + ":" + erasure(owner, member.tpe) + member.locationString + " =\n " + bridgeDef); bridgeDef |