diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 50cd6a8d6ae4..39774c5886b0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2824,7 +2824,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val tupleXXLobj = untpd.ref(defn.TupleXXLModule.termRef) val app = untpd.cpy.Apply(tree)(tupleXXLobj, elems.map(untpd.TypedSplice(_))) .withSpan(tree.span) - val app1 = typed(app, defn.TupleXXLClass.typeRef) + val app1 = typed(app, if ctx.mode.is(Mode.Pattern) then pt else defn.TupleXXLClass.typeRef) if (ctx.mode.is(Mode.Pattern)) app1 else { val elemTpes = elems.lazyZip(pts).map((elem, pt) => diff --git a/tests/run/i16213.scala b/tests/run/i16213.scala new file mode 100644 index 000000000000..e8e4968e598b --- /dev/null +++ b/tests/run/i16213.scala @@ -0,0 +1,11 @@ +object Test: + def main(args: Array[String]): Unit = + test(1) // was: ClassCastException: java.lang.Integer cannot be cast to scala.runtime.TupleXXL + + def test(any: Any) = any match + case ( + _, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _, _, + _, _, _ + ) => 23 + case _ => -1