diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index f20c2d313ec7..ed0ff5e0bd2f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2198,7 +2198,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer /** Type a case. */ def typedCase(tree: untpd.CaseDef, sel: Tree, wideSelType: Type, pt: Type)(using Context): CaseDef = { val originalCtx = ctx - val gadtCtx: Context = ctx.fresh.setFreshGADTBounds.setNewScope + val gadtCtx: Context = ctx.fresh.setFreshGADTBounds def caseRest(pat: Tree)(using Context) = { val pt1 = instantiateMatchTypeProto(pat, pt) match { @@ -2228,7 +2228,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val pat1 = typedPattern(tree.pat, wideSelType)(using gadtCtx) caseRest(pat1)( using Nullables.caseContext(sel, pat1)( - using gadtCtx)) + using gadtCtx.fresh.setNewScope)) } def typedLabeled(tree: untpd.Labeled)(using Context): Labeled = { diff --git a/tests/pos/i21742.1.scala b/tests/pos/i21742.1.scala new file mode 100644 index 000000000000..c9c1a94b222c --- /dev/null +++ b/tests/pos/i21742.1.scala @@ -0,0 +1,5 @@ +case class C(n: Int, ds: Double*) +class Test: + def m(using n: Int): Int = n + 1 + def t(): Unit = + C(1, 2, 3, 4) match { case C(given Int, ds*) => m } diff --git a/tests/pos/i21742.2.scala b/tests/pos/i21742.2.scala new file mode 100644 index 000000000000..83dc4b6ad46f --- /dev/null +++ b/tests/pos/i21742.2.scala @@ -0,0 +1,5 @@ +case class C(n: Int, ds: Seq[Double]) +class Test: + def m(using n: Int): Int = n + 1 + def t(): Unit = + C(1, Seq(2, 3, 4)) match { case C(given Int, ds) => m }