Skip to content

Commit 65972b4

Browse files
authored
Cover patterns using reflect.TypeTest in isMatchTypeShaped (#19923)
Fixes #19692
2 parents 96faa3e + 0942eef commit 65972b4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
18261826
// check `pat` here and throw away the result.
18271827
val gadtCtx: Context = ctx.fresh.setFreshGADTBounds
18281828
val pat1 = typedPattern(pat, selType)(using gadtCtx)
1829-
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1)): @unchecked
1829+
val tpt = tpd.unbind(tpd.unsplice(pat1)) match
1830+
case Typed(_, tpt) => tpt
1831+
case UnApply(fun, _, p1 :: _) if fun.symbol == defn.TypeTest_unapply => p1
18301832
instantiateMatchTypeProto(pat1, pt) match {
18311833
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
18321834
case _ => false

tests/pos/i19692.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
trait UsingTypeTest[B](using reflect.TypeTest[Int, B]):
3+
4+
type M[U <: Int] = U match
5+
case B => String
6+
7+
def m(t: Int): M[Int] = t match
8+
case _: B => "hello"

0 commit comments

Comments
 (0)