Skip to content

Commit 82a0bd3

Browse files
authored
Merge pull request #1325 from dotty-staging/overloaded-extractor
better handling of overloaded extractors
2 parents c7d1826 + cece884 commit 82a0bd3

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,11 @@ trait Applications extends Compatibility { self: Typer =>
709709
// try first for non-overloaded, then for overloaded ocurrences
710710
def tryWithName(name: TermName)(fallBack: Tree => Tree)(implicit ctx: Context): Tree =
711711
tryEither {
712-
implicit ctx => typedExpr(untpd.Select(qual, name), genericProto)
712+
implicit ctx => typedExpr(untpd.Select(qual, name), specificProto)
713713
} {
714714
(sel, _) =>
715715
tryEither {
716-
implicit ctx => typedExpr(untpd.Select(qual, name), specificProto)
716+
implicit ctx => typedExpr(untpd.Select(qual, name), genericProto)
717717
} {
718718
(_, _) => fallBack(sel)
719719
}

tests/pos/i1318.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
object Foo {
2+
class S(i: Int)
3+
case class T(i: Int) extends S(i)
4+
5+
object T {
6+
def unapply(s: S): Option[(Int, Int)] = Some(5, 6)
7+
// def unapply(o: Object): Option[(Int, Int, Int)] = Some(5, 6, 7)
8+
}
9+
10+
val s = new S(5)
11+
12+
s match {
13+
// case T(x, y, z) => println(x + y + z)
14+
case T(x, y) => println(x + y)
15+
case T(x) => println(x)
16+
case _ => println("not match")
17+
}
18+
}
19+
20+
object Bar {
21+
case class T(i: Int)
22+
class S(i: Int) extends T(i)
23+
24+
object T {
25+
def unapply(s: S): Option[(Int, Int)] = Some(5, 6)
26+
// def unapply(o: Object): Option[(Int, Int, Int)] = Some(5, 6, 7)
27+
}
28+
29+
val s = new S(5)
30+
31+
s match {
32+
// case T(x, y, z) => println(x + y + z)
33+
case T(x, y) => println(x + y)
34+
case T(x) => println(x)
35+
case _ => println("not match")
36+
}
37+
}
38+

0 commit comments

Comments
 (0)