diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 5fc3b2569898..33805e0f3cdd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -149,10 +149,12 @@ object Applications { } def unapplyArgs(unapplyResult: Type, unapplyFn: Tree, args: List[untpd.Tree], pos: SourcePosition)(using Context): List[Type] = { - - val unapplyName = unapplyFn match // tolerate structural `unapply`, which does not have a symbol - case TypeApply(fn: RefTree, _) => fn.name - case fn: RefTree => fn.name + def getName(fn: Tree): Name = + fn match + case TypeApply(fn, _) => getName(fn) + case Apply(fn, _) => getName(fn) + case fn: RefTree => fn.name + val unapplyName = getName(unapplyFn) // tolerate structural `unapply`, which does not have a symbol def getTp = extractorMemberType(unapplyResult, nme.get, pos) diff --git a/tests/pos/i8972.scala b/tests/pos/i8972.scala new file mode 100644 index 000000000000..e4678718aa4f --- /dev/null +++ b/tests/pos/i8972.scala @@ -0,0 +1,9 @@ +trait Num: + type Nat + +object IsInt: + def unapply(using num: Num)(sc: num.Nat): Option[Int] = ??? + +def test(using num: Num)(x: num.Nat) = + x match + case IsInt(i) =>