From 52bc468d7ad80158a64fb9bfe1f5e377866fe4e7 Mon Sep 17 00:00:00 2001 From: Yoonjae Jeon Date: Wed, 5 Nov 2025 16:23:36 +0900 Subject: [PATCH 1/2] Fix crash in Selectable unapply with custom applyDynamic --- compiler/src/dotty/tools/dotc/typer/Dynamic.scala | 4 ++-- tests/neg/i24168.scala | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i24168.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Dynamic.scala b/compiler/src/dotty/tools/dotc/typer/Dynamic.scala index 8d48651ad6e9..683244cc8795 100644 --- a/compiler/src/dotty/tools/dotc/typer/Dynamic.scala +++ b/compiler/src/dotty/tools/dotc/typer/Dynamic.scala @@ -43,9 +43,9 @@ object DynamicUnapply { def unapply(tree: tpd.Tree): Option[List[tpd.Tree]] = tree match case TypeApply(Select(qual, name), _) if name == nme.asInstanceOfPM => unapply(qual) - case Apply(Apply(Select(selectable, fname), Literal(Constant(name)) :: ctag :: Nil), _ :: implicits) + case Apply(Apply(Select(selectable, fname), Literal(Constant(name)) :: restArgs), _ :: implicits) if fname == nme.applyDynamic && (name == "unapply" || name == "unapplySeq") => - Some(selectable :: ctag :: implicits) + Some(selectable :: (restArgs ::: implicits)) case _ => None } diff --git a/tests/neg/i24168.scala b/tests/neg/i24168.scala new file mode 100644 index 000000000000..566fb594bad9 --- /dev/null +++ b/tests/neg/i24168.scala @@ -0,0 +1,12 @@ +trait Generic extends Selectable: + def applyDynamic(name: String)(args: Any*): Any = () + +val foo: Generic { + def unapply(x: Int): Option[Unit] +} = new Generic: + def unapply(x: Int): Option[Unit] = Some(()) + +def x = + 42 match + case foo(()) => println("lol") + From cf0a6b8a2b50a9c9a3d1587edf8e4bc2db38a787 Mon Sep 17 00:00:00 2001 From: Yoonjae Jeon Date: Wed, 5 Nov 2025 18:17:22 +0900 Subject: [PATCH 2/2] fix test --- tests/neg/i24168.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/neg/i24168.scala b/tests/neg/i24168.scala index 566fb594bad9..b554e4d817d5 100644 --- a/tests/neg/i24168.scala +++ b/tests/neg/i24168.scala @@ -8,5 +8,5 @@ val foo: Generic { def x = 42 match - case foo(()) => println("lol") + case foo(()) => println("lol") // error