Skip to content

Commit d7c1c27

Browse files
committed
Allow dependent method type for unapply.
1 parent 3129c1c commit d7c1c27

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,7 @@ trait Applications extends Compatibility { self: Typer =>
736736
}
737737

738738
unapplyFn.tpe.widen match {
739-
case mt: MethodType if mt.paramTypes.length == 1 && !mt.isDependent =>
740-
val m = mt
739+
case mt: MethodType if mt.paramTypes.length == 1 =>
741740
val unapplyArgType = mt.paramTypes.head
742741
unapp.println(i"unapp arg tpe = $unapplyArgType, pt = $selType")
743742
def wpt = widenForMatchSelector(selType) // needed?
@@ -778,7 +777,7 @@ trait Applications extends Compatibility { self: Typer =>
778777
tree.pos)
779778
}
780779

781-
val dummyArg = dummyTreeOfType(unapplyArgType)
780+
val dummyArg = dummyTreeOfType(ownType)
782781
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))
783782
val unapplyImplicits = unapplyApp match {
784783
case Apply(Apply(unapply, `dummyArg` :: Nil), args2) => assert(args2.nonEmpty); args2

tests/pos/dependent-extractors.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
3+
abstract class C { type T; val x: T }
4+
5+
val c = new C { type T = Int; val x = 1 }
6+
7+
object X { def unapply(x: C): Some[x.T] = Some(x.x) }
8+
9+
val y = c match { case X(y) => y }
10+
val y1: Int = y
11+
12+
val z = (c: Any) match { case X(y) => y }
13+
val z1: C#T = z
14+
}

0 commit comments

Comments
 (0)