Skip to content

Commit 944554c

Browse files
Backport "Cover patterns using reflect.TypeTest in isMatchTypeShaped" to LTS (#21002)
Backports #19923 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 27ecfe2 + d76a553 commit 944554c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17381738
// check `pat` here and throw away the result.
17391739
val gadtCtx: Context = ctx.fresh.setFreshGADTBounds
17401740
val pat1 = typedPattern(pat, selType)(using gadtCtx)
1741-
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1)): @unchecked
1741+
val tpt = tpd.unbind(tpd.unsplice(pat1)) match
1742+
case Typed(_, tpt) => tpt
1743+
case UnApply(fun, _, p1 :: _) if fun.symbol == defn.TypeTest_unapply => p1
17421744
instantiateMatchTypeProto(pat1, pt) match {
17431745
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
17441746
case _ => false

Diff for: tests/pos/i19692.scala

+8
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)