Skip to content

Commit

Permalink
more defensive bridging to extractor: consider boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaanm committed May 10, 2012
1 parent 782dad7 commit 289aced
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/compiler/scala/tools/nsc/transform/Erasure.scala
Expand Up @@ -480,16 +480,22 @@ abstract class Erasure extends AddInterfaces
// TODO: should we do this for user-defined unapplies as well? // 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 // does the first argument list have exactly one argument -- for user-defined unapplies we can't be sure
def maybeWrap(bridgingCall: Tree): Tree = { 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) (member.name == nme.unapply || member.name == nme.unapplySeq)
&& !afterErasure((member.tpe <:< other.tpe))) // no static guarantees (TODO: is the subtype test ever true?) && !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) val typeTest = gen.mkIsInstanceOf(REF(bridge.firstParam), member.tpe.params.head.tpe)
IF (typeTest) THEN bridgingCall ELSE REF(NoneModule) IF (typeTest) THEN bridgingCall ELSE zero
} } else bridgingCall
else bridgingCall
} }
val rhs = member.tpe match { val rhs = member.tpe match {
case MethodType(Nil, ConstantType(c)) => Literal(c) case MethodType(Nil, ConstantType(c)) => Literal(c)
Expand Down

0 comments on commit 289aced

Please sign in to comment.