Skip to content

Commit

Permalink
Only recurse for TypeTests checkability with normalizing match types
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Apr 25, 2024
1 parent abb6909 commit 1f9987c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5214,6 +5214,10 @@ object Types extends TypeUtils {
def thatReducesUsingGadt(tp: Type)(using Context): Boolean = tp.underlyingMatchType match
case mt: MatchType => mt.reducesUsingGadt
case _ => false

object Normalizing:
def unapply(tp: Type)(using Context): Option[Type] =
Some(tp.tryNormalize).filter(_.exists)
}

enum MatchTypeCasePattern:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ object TypeTestsCasts {
def recur(X: Type, P: Type): String = trace(s"recur(${X.show}, ${P.show})") {
(X <:< P) ||| P.dealias.match
case _: SingletonType => ""
case tp if tp.isMatchAlias => recur(X, tp.tryNormalize)
case MatchType.Normalizing(tp) => recur(X, tp)
case _: TypeProxy
if isAbstract(P) => i"it refers to an abstract type member or type parameter"
case defn.ArrayOf(tpT) =>
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i13433c/A_1.scala → tests/warn/i13433c/A_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ type MS = Matcher[S]

type S2 = MS
type MS2 = Matcher[S2]

type Mstuck = Matcher[Nothing]
3 changes: 2 additions & 1 deletion tests/pos/i13433c/B_2.scala → tests/warn/i13433c/B_2.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//> using options -Xfatal-warnings -deprecation -feature

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

0 comments on commit 1f9987c

Please sign in to comment.