Skip to content

Commit

Permalink
replace widen with <:<
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickern committed May 17, 2024
1 parent 2c349c1 commit 7279bf7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,11 @@ object PatternMatcher {
*/
private def collectSwitchCases(scrutinee: Tree, plan: SeqPlan): List[(List[Tree], Plan)] = {
def isSwitchableType(tpe: Type): Boolean =
(tpe isRef defn.IntClass) ||
(tpe isRef defn.ByteClass) ||
(tpe isRef defn.ShortClass) ||
(tpe isRef defn.CharClass) ||
(tpe isRef defn.StringClass)
(tpe <:< defn.IntType) ||
(tpe <:< defn.ByteType) ||
(tpe <:< defn.ShortType) ||
(tpe <:< defn.CharType) ||
(tpe <:< defn.StringType)

val seen = mutable.Set[Any]()

Expand Down Expand Up @@ -868,7 +868,7 @@ object PatternMatcher {
(Nil, plan) :: Nil
}

if (isSwitchableType(scrutinee.tpe.widen.widenSingletons())) recur(plan)
if (isSwitchableType(scrutinee.tpe)) recur(plan)
else Nil
}

Expand All @@ -889,9 +889,8 @@ object PatternMatcher {
*/

val (primScrutinee, scrutineeTpe) =
val tpe = scrutinee.tpe.widen.widenSingletons()
if (tpe.isRef(defn.IntClass)) (scrutinee, defn.IntType)
else if (tpe.isRef(defn.StringClass)) (scrutinee, defn.StringType)
if (scrutinee.tpe <:< defn.IntType) (scrutinee, defn.IntType)
else if (scrutinee.tpe <:< defn.StringType) (scrutinee, defn.StringType)
else (scrutinee.select(nme.toInt), defn.IntType)

def primLiteral(lit: Tree): Tree =
Expand Down

0 comments on commit 7279bf7

Please sign in to comment.