File tree 2 files changed +32
-1
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -1518,7 +1518,15 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1518
1518
1519
1519
/** Replace each alternative by its apply members where necessary */
1520
1520
def applyMembers (alt : TermRef ): List [TermRef ] =
1521
- if (tryApply(alt)) alt.member(nme.apply).alternatives.map(TermRef (alt, nme.apply, _))
1521
+ if (tryApply(alt)) {
1522
+ val qual = alt.widen match {
1523
+ case pt : PolyType =>
1524
+ wildApprox(pt.resultType)
1525
+ case _ =>
1526
+ alt
1527
+ }
1528
+ qual.member(nme.apply).alternatives.map(TermRef (alt, nme.apply, _))
1529
+ }
1522
1530
else alt :: Nil
1523
1531
1524
1532
/** Fall back from an apply method to its original alternative */
Original file line number Diff line number Diff line change
1
+ class A {
2
+ def foo1 (x : Int ): Int = x
3
+ def foo1 [T ]: String => T = ???
4
+
5
+ foo1(" " ) // ok
6
+
7
+ def foo2 (x : Int ): Int = x
8
+ def foo2 [T ]: T => String = ???
9
+
10
+ foo2(1 ): String // ok
11
+ foo2(" " ) // ok, unlike Scala 2
12
+
13
+ def foo3 (x : Any ): Any = x
14
+ def foo3 [T <: Int ]: T => T = x => x
15
+
16
+ val a = foo3(1 ) // ok
17
+ val b : Int = a // ok, unlike Scala 2 which prefers the first overload
18
+
19
+ def foo4 (x : Any ): Any = x
20
+ def foo4 [T >: Int ]: T => T = x => x
21
+
22
+ val c = foo4(1 ) // error, unlike Scala 2 this is ambiguous
23
+ }
You can’t perform that action at this time.
0 commit comments