Skip to content

Commit aa2f4a6

Browse files
committed
Merge pull request scala#3524 from paulp/pr/8280
SI-8280 regression in implicit selection.
2 parents c83e01d + 1067e23 commit aa2f4a6

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ trait Implicits {
306306
*/
307307
object Function1 {
308308
val Sym = FunctionClass(1)
309-
def unapply(tp: Type) = tp baseType Sym match {
309+
// It is tempting to think that this should be inspecting "tp baseType Sym"
310+
// rather than tp. See test case run/t8280 and the commit message which
311+
// accompanies it for explanation why that isn't done.
312+
def unapply(tp: Type) = tp match {
310313
case TypeRef(_, Sym, arg1 :: arg2 :: _) => Some((arg1, arg2))
311314
case _ => None
312315
}

test/files/run/t8280.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Int
2+
Int
3+
Int
4+
Int
5+
Int
6+
Int
7+
Int
8+
Int
9+
Int

test/files/run/t8280.scala

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import scala.language.implicitConversions
2+
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
Moop1.ob1
6+
Moop1.ob2
7+
Moop1.ob3
8+
Moop2.ob1
9+
Moop2.ob2
10+
Moop2.ob3
11+
Moop3.ob1
12+
Moop3.ob2
13+
Moop3.ob3
14+
}
15+
}
16+
17+
// int object vs.
18+
object Moop1 {
19+
object ob1 {
20+
implicit object f1 extends (Int => String) { def apply(x: Int): String = "Int" }
21+
implicit object f2 extends (Long => String) { def apply(x: Long): String = "Long" }
22+
23+
println(5: String)
24+
}
25+
object ob2 {
26+
implicit object f1 extends (Int => String) { def apply(x: Int): String = "Int" }
27+
implicit def f2(x: Long): String = "Long"
28+
29+
println(5: String)
30+
}
31+
object ob3 {
32+
implicit object f1 extends (Int => String) { def apply(x: Int): String = "Int" }
33+
implicit val f2: Long => String = _ => "Long"
34+
35+
println(5: String)
36+
}
37+
}
38+
39+
// int def vs.
40+
object Moop2 {
41+
object ob1 {
42+
implicit def f1(x: Int): String = "Int"
43+
implicit object f2 extends (Long => String) { def apply(x: Long): String = "Long" }
44+
45+
println(5: String)
46+
}
47+
object ob2 {
48+
implicit def f1(x: Int): String = "Int"
49+
implicit def f2(x: Long): String = "Long"
50+
51+
println(5: String)
52+
}
53+
object ob3 {
54+
implicit def f1(x: Int): String = "Int"
55+
implicit val f2: Long => String = _ => "Long"
56+
57+
println(5: String)
58+
}
59+
}
60+
61+
// int val vs.
62+
object Moop3 {
63+
object ob1 {
64+
implicit val f1: Int => String = _ => "Int"
65+
implicit object f2 extends (Long => String) { def apply(x: Long): String = "Long" }
66+
67+
println(5: String)
68+
}
69+
object ob2 {
70+
implicit val f1: Int => String = _ => "Int"
71+
implicit def f2(x: Long): String = "Long"
72+
73+
println(5: String)
74+
}
75+
object ob3 {
76+
implicit val f1: Int => String = _ => "Int"
77+
implicit val f2: Long => String = _ => "Long"
78+
79+
println(5: String)
80+
}
81+
}
82+

0 commit comments

Comments
 (0)