Permalink
Browse files

more defensive bridging to extractor: consider boolean

  • Loading branch information...
adriaanm committed May 10, 2012
1 parent 782dad7 commit 289aced4a9a3f3ce4e351b3065a7f1ca4e5a37db
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -480,16 +480,22 @@ abstract class Erasure extends AddInterfaces
// TODO: should we do this for user-defined unapplies as well?
// does the first argument list have exactly one argument -- for user-defined unapplies we can't be sure
def maybeWrap(bridgingCall: Tree): Tree = {
val canReturnNone = ( // can't statically know which member is going to be selected, so don't let this depend on member.isSynthetic
val guardExtractor = ( // can't statically know which member is going to be selected, so don't let this depend on member.isSynthetic
(member.name == nme.unapply || member.name == nme.unapplySeq)
&& !afterErasure((member.tpe <:< other.tpe))) // no static guarantees (TODO: is the subtype test ever true?)
if (canReturnNone) {
import CODE._
import CODE._
val _false = FALSE_typed
val pt = member.tpe.resultType
lazy val zero =
if (_false.tpe <:< pt) _false
else if (NoneModule.tpe <:< pt) REF(NoneModule)
else EmptyTree
if (guardExtractor && (zero ne EmptyTree)) {
val typeTest = gen.mkIsInstanceOf(REF(bridge.firstParam), member.tpe.params.head.tpe)
IF (typeTest) THEN bridgingCall ELSE REF(NoneModule)
}
else bridgingCall
IF (typeTest) THEN bridgingCall ELSE zero
} else bridgingCall
}
val rhs = member.tpe match {
case MethodType(Nil, ConstantType(c)) => Literal(c)

0 comments on commit 289aced

Please sign in to comment.