From d76a553073d1083fbf650140d597e3df4adaf469 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 11 Mar 2024 18:36:48 +0100 Subject: [PATCH] Cover patterns using `reflet.TypeTest` in isMatchTypeShaped [Cherry-picked 0942eef54c6c2eb31118175d9777a344c79275f7] --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 4 +++- tests/pos/i19692.scala | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i19692.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 7637bb3d5e2a..2ec42604ad08 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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 diff --git a/tests/pos/i19692.scala b/tests/pos/i19692.scala new file mode 100644 index 000000000000..7cc64e59ff07 --- /dev/null +++ b/tests/pos/i19692.scala @@ -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" \ No newline at end of file