Skip to content

Commit bbce221

Browse files
committed
Fix #1036
Achieved by tweaking from where we get the parameter types of an eta-expansion.
1 parent 1aa8fbb commit bbce221

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
14601460
}
14611461
case wtp: MethodType if !pt.isInstanceOf[SingletonType] =>
14621462
val arity =
1463-
if (defn.isFunctionType(pt)) defn.functionArity(pt)
1463+
if (defn.isFunctionType(pt))
1464+
if (!isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none))
1465+
// if method type is fully defined, but expected type is not,
1466+
// prioritize method parameter types as parameter types of the eta-expanded closure
1467+
0
1468+
else defn.functionArity(pt)
14641469
else if (pt eq AnyFunctionProto) wtp.paramTypes.length
14651470
else -1
14661471
if (arity >= 0 && !tree.symbol.isConstructor)

tests/pos/i1036.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
def second[sA, sB <: sA](foo: sA, bar: sB): sB = bar
3+
def third[A, B >: A](foo: A, bar: B): B = bar
4+
def expectString(s: String) = s
5+
6+
def test = {
7+
val x = second(Set.empty[String], Set.empty)
8+
x map expectString
9+
second(Set.empty[String], Set.empty) map expectString
10+
third(Set.empty[String], Set.empty) map expectString
11+
}
12+
}

0 commit comments

Comments
 (0)