Skip to content

Commit c9c7187

Browse files
authored
Fix crash in Selectable unapply with custom applyDynamic (#24343)
closes: #24168
1 parent 81da39a commit c9c7187

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Dynamic.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ object DynamicUnapply {
4343
def unapply(tree: tpd.Tree): Option[List[tpd.Tree]] = tree match
4444
case TypeApply(Select(qual, name), _) if name == nme.asInstanceOfPM =>
4545
unapply(qual)
46-
case Apply(Apply(Select(selectable, fname), Literal(Constant(name)) :: ctag :: Nil), _ :: implicits)
46+
case Apply(Apply(Select(selectable, fname), Literal(Constant(name)) :: restArgs), _ :: implicits)
4747
if fname == nme.applyDynamic && (name == "unapply" || name == "unapplySeq") =>
48-
Some(selectable :: ctag :: implicits)
48+
Some(selectable :: (restArgs ::: implicits))
4949
case _ =>
5050
None
5151
}

tests/neg/i24168.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Generic extends Selectable:
2+
def applyDynamic(name: String)(args: Any*): Any = ()
3+
4+
val foo: Generic {
5+
def unapply(x: Int): Option[Unit]
6+
} = new Generic:
7+
def unapply(x: Int): Option[Unit] = Some(())
8+
9+
def x =
10+
42 match
11+
case foo(()) => println("lol") // error
12+

0 commit comments

Comments
 (0)