@@ -711,9 +711,14 @@ object PatternMatcher {
711
711
(tpe isRef defn.ShortClass ) ||
712
712
(tpe isRef defn.CharClass )
713
713
714
- def isIntConst (tree : Tree ) = tree match {
715
- case Literal (const) => const.isIntRange
716
- case _ => false
714
+ val seen = mutable.Set [Int ]()
715
+
716
+ def isNewIntConst (tree : Tree ) = tree match {
717
+ case Literal (const) if const.isIntRange && ! seen.contains(const.intValue) =>
718
+ seen += const.intValue
719
+ true
720
+ case _ =>
721
+ false
717
722
}
718
723
719
724
// An extractor to recover the shape of plans that can become alternatives
@@ -725,7 +730,7 @@ object PatternMatcher {
725
730
val alts = List .newBuilder[Tree ]
726
731
def rec (innerPlan : Plan ): Boolean = innerPlan match {
727
732
case SeqPlan (TestPlan (EqualTest (tree), scrut, _, ReturnPlan (`innerLabel`)), tail)
728
- if scrut === scrutinee && isIntConst (tree) =>
733
+ if scrut === scrutinee && isNewIntConst (tree) =>
729
734
alts += tree
730
735
rec(tail)
731
736
case ReturnPlan (`outerLabel`) =>
@@ -746,7 +751,7 @@ object PatternMatcher {
746
751
747
752
def recur (plan : Plan ): List [(List [Tree ], Plan )] = plan match {
748
753
case SeqPlan (testPlan @ TestPlan (EqualTest (tree), scrut, _, ons), tail)
749
- if scrut === scrutinee && isIntConst(tree ) && ! canFallThrough(ons ) =>
754
+ if scrut === scrutinee && ! canFallThrough(ons ) && isNewIntConst(tree ) =>
750
755
(tree :: Nil , ons) :: recur(tail)
751
756
case SeqPlan (AlternativesPlan (alts, ons), tail) =>
752
757
(alts, ons) :: recur(tail)
0 commit comments