Skip to content

Commit 348184f

Browse files
Merge pull request #9004 from dotty-staging/fix-#8972
Fix #8972: Handle applications in Unapply fun
2 parents 0e6aa7e + 161bc83 commit 348184f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ object Applications {
149149
}
150150

151151
def unapplyArgs(unapplyResult: Type, unapplyFn: Tree, args: List[untpd.Tree], pos: SourcePosition)(using Context): List[Type] = {
152-
153-
val unapplyName = unapplyFn match // tolerate structural `unapply`, which does not have a symbol
154-
case TypeApply(fn: RefTree, _) => fn.name
155-
case fn: RefTree => fn.name
152+
def getName(fn: Tree): Name =
153+
fn match
154+
case TypeApply(fn, _) => getName(fn)
155+
case Apply(fn, _) => getName(fn)
156+
case fn: RefTree => fn.name
157+
val unapplyName = getName(unapplyFn) // tolerate structural `unapply`, which does not have a symbol
156158

157159
def getTp = extractorMemberType(unapplyResult, nme.get, pos)
158160

tests/pos/i8972.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Num:
2+
type Nat
3+
4+
object IsInt:
5+
def unapply(using num: Num)(sc: num.Nat): Option[Int] = ???
6+
7+
def test(using num: Num)(x: num.Nat) =
8+
x match
9+
case IsInt(i) =>

0 commit comments

Comments
 (0)