Skip to content

Commit 1f51376

Browse files
authored
Merge pull request #3905 from dotty-staging/fix-#2104
Fix #2104: Instantiate unapply result type variables
2 parents 1fb82a5 + 540b011 commit 1f51376

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
920920
val ownType =
921921
if (selType <:< unapplyArgType) {
922922
unapp.println(i"case 1 $unapplyArgType ${ctx.typerState.constraint}")
923+
fullyDefinedType(unapplyArgType, "pattern selector", tree.pos)
923924
selType
924925
} else if (isSubTypeOfParent(unapplyArgType, selType)(ctx.addMode(Mode.GADTflexible))) {
925926
maximizeType(unapplyArgType) match {
@@ -952,7 +953,6 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
952953
ex"Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $selType",
953954
tree.pos)
954955
}
955-
956956
val dummyArg = dummyTreeOfType(ownType)
957957
val unapplyApp = typedExpr(untpd.TypedSplice(Apply(unapplyFn, dummyArg :: Nil)))
958958
val unapplyImplicits = unapplyApp match {

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
811811
.expect { (ictx, messages) =>
812812
implicit val ctx: Context = ictx
813813

814-
assertMessageCount(1, messages)
815-
val AnonymousFunctionMissingParamType(param, args, _, pt) :: Nil = messages
814+
val AnonymousFunctionMissingParamType(param, args, _, pt) = messages.last
816815
assertEquals("x$1", param.show)
817816
assertEquals(s"List(ValDef(${param.show},TypeTree,EmptyTree))", args.toString)
818817
assertEquals("?", pt.show)

tests/pos/i2104.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
case class Pair[A, B](_1: A, _2: B)
2+
3+
trait Cons[+H, +T]
4+
5+
object Cons {
6+
def apply[H, T](h: H, t: T): Cons[H, T] = ???
7+
def unapply[H, T](t: Cons[H, T]): Option[Pair[H, T]] = ???
8+
}
9+
10+
11+
12+
object Test {
13+
def main(args: Array[String]): Unit = {
14+
Cons(Option(1), None) match {
15+
case Cons(Some(i), None) =>
16+
i: Int // error: found: Any(i), requires: Int
17+
assert(i == 1)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)