Skip to content

Commit

Permalink
Backport "Cover patterns using reflect.TypeTest in isMatchTypeShape…
Browse files Browse the repository at this point in the history
…d" to LTS (#21002)

Backports #19923 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 4, 2024
2 parents 27ecfe2 + d76a553 commit 944554c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// check `pat` here and throw away the result.
val gadtCtx: Context = ctx.fresh.setFreshGADTBounds
val pat1 = typedPattern(pat, selType)(using gadtCtx)
val Typed(_, tpt) = tpd.unbind(tpd.unsplice(pat1)): @unchecked
val tpt = tpd.unbind(tpd.unsplice(pat1)) match
case Typed(_, tpt) => tpt
case UnApply(fun, _, p1 :: _) if fun.symbol == defn.TypeTest_unapply => p1
instantiateMatchTypeProto(pat1, pt) match {
case defn.MatchCase(patternTp, _) => tpt.tpe frozen_=:= patternTp
case _ => false
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i19692.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

trait UsingTypeTest[B](using reflect.TypeTest[Int, B]):

type M[U <: Int] = U match
case B => String

def m(t: Int): M[Int] = t match
case _: B => "hello"

0 comments on commit 944554c

Please sign in to comment.