@@ -145,7 +145,6 @@ object PatternMatcher {
145
145
case class ReturnPlan (var label : TermSymbol ) extends Plan
146
146
case class SeqPlan (var head : Plan , var tail : Plan ) extends Plan
147
147
case class ResultPlan (var tree : Tree ) extends Plan
148
- case object NoOpPlan extends Plan
149
148
150
149
object TestPlan {
151
150
def apply (test : Test , sym : Symbol , span : Span , ons : Plan ): TestPlan =
@@ -336,22 +335,18 @@ object PatternMatcher {
336
335
patternPlan(casted, pat, onSuccess)
337
336
})
338
337
case UnApply (extractor, implicits, args) =>
339
- val mt @ MethodType (_) = extractor.tpe.widen
340
- var unapp = extractor.appliedTo(ref(scrutinee).ensureConforms(mt.paramInfos.head))
341
- if (implicits.nonEmpty) unapp = unapp.appliedToArgs(implicits)
342
- val scrutineeTpe = scrutinee.info.widenDealias
343
- if (scrutineeTpe.isBottomType || scrutineeTpe.isNullType) {
344
- // If the value being matched against has type `Nothing`, then the unapply code
345
- // will never execute.
346
- // If it has type `Null`, then the `NonNullTest` below guarantees that the unapply code
347
- // won't execute either.
348
- // So we don't need a plan in this case.
349
- NoOpPlan
338
+ val unappPlan = if (defn.isBottomType(scrutinee.info)) {
339
+ // Generate a throwaway but type-correct plan.
340
+ // This plan will never execute because it'll be guarded by a `NonNullTest`.
341
+ ResultPlan (tpd.Throw (tpd.Literal (Constant (null ))))
350
342
} else {
351
- val unappPlan = unapplyPlan(unapp, args)
352
- if (scrutinee.info.isNotNull || nonNull(scrutinee)) unappPlan
353
- else TestPlan (NonNullTest , scrutinee, tree.span, unappPlan)
343
+ val mt @ MethodType (_) = extractor.tpe.widen
344
+ var unapp = extractor.appliedTo(ref(scrutinee).ensureConforms(mt.paramInfos.head))
345
+ if (implicits.nonEmpty) unapp = unapp.appliedToArgs(implicits)
346
+ unapplyPlan(unapp, args)
354
347
}
348
+ if (scrutinee.info.isNotNull || nonNull(scrutinee)) unappPlan
349
+ else TestPlan (NonNullTest , scrutinee, tree.span, unappPlan)
355
350
case Bind (name, body) =>
356
351
if (name == nme.WILDCARD ) patternPlan(scrutinee, body, onSuccess)
357
352
else {
@@ -431,7 +426,6 @@ object PatternMatcher {
431
426
case plan : ReturnPlan => apply(plan)
432
427
case plan : SeqPlan => apply(plan)
433
428
case plan : ResultPlan => plan
434
- case NoOpPlan => NoOpPlan
435
429
}
436
430
}
437
431
@@ -708,7 +702,6 @@ object PatternMatcher {
708
702
private def canFallThrough (plan : Plan ): Boolean = plan match {
709
703
case _:ReturnPlan | _:ResultPlan => false
710
704
case _:TestPlan | _:LabeledPlan => true
711
- case NoOpPlan => true
712
705
case LetPlan (_, body) => canFallThrough(body)
713
706
case SeqPlan (_, tail) => canFallThrough(tail)
714
707
}
@@ -872,9 +865,6 @@ object PatternMatcher {
872
865
case ResultPlan (tree) =>
873
866
if (tree.tpe <:< defn.NothingType ) tree // For example MatchError
874
867
else Return (tree, ref(resultLabel))
875
- case NoOpPlan =>
876
- // TODO(abeln): optimize away
877
- Literal (Constant (true ))
878
868
}
879
869
}
880
870
@@ -913,8 +903,6 @@ object PatternMatcher {
913
903
showPlan(tail)
914
904
case ResultPlan (tree) =>
915
905
sb.append(tree.show)
916
- case NoOpPlan =>
917
- sb.append(" NoOp" )
918
906
}
919
907
}
920
908
showPlan(plan)
0 commit comments