Skip to content

Commit 1f9987c

Browse files
Only recurse for TypeTests checkability with normalizing match types
1 parent abb6909 commit 1f9987c

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,6 +5214,10 @@ object Types extends TypeUtils {
52145214
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingMatchType match
52155215
case mt: MatchType => mt.reducesUsingGadt
52165216
case _ => false
5217+
5218+
object Normalizing:
5219+
def unapply(tp: Type)(using Context): Option[Type] =
5220+
Some(tp.tryNormalize).filter(_.exists)
52175221
}
52185222

52195223
enum MatchTypeCasePattern:

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ object TypeTestsCasts {
135135
def recur(X: Type, P: Type): String = trace(s"recur(${X.show}, ${P.show})") {
136136
(X <:< P) ||| P.dealias.match
137137
case _: SingletonType => ""
138-
case tp if tp.isMatchAlias => recur(X, tp.tryNormalize)
138+
case MatchType.Normalizing(tp) => recur(X, tp)
139139
case _: TypeProxy
140140
if isAbstract(P) => i"it refers to an abstract type member or type parameter"
141141
case defn.ArrayOf(tpT) =>

tests/pos/i13433c/A_1.scala renamed to tests/warn/i13433c/A_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ type MS = Matcher[S]
2323

2424
type S2 = MS
2525
type MS2 = Matcher[S2]
26+
27+
type Mstuck = Matcher[Nothing]

tests/pos/i13433c/B_2.scala renamed to tests/warn/i13433c/B_2.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//> using options -Xfatal-warnings -deprecation -feature
21

32
@main def main = {
43
println(patternMatch[String]("abc"))
@@ -19,4 +18,6 @@
1918
if s.isInstanceOf[S2] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None}))
2019
println(patternMatch[String]("abc")(using (s: Any) => {
2120
if s.isInstanceOf[MS2] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None}))
21+
println(patternMatch[String]("abc")(using (s: Any) => {
22+
if s.isInstanceOf[Mstuck] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None})) // warn
2223
}

0 commit comments

Comments
 (0)