Skip to content

Commit 5c111ff

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

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,12 +1460,16 @@ 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+
// prioritize method parameter types over expected types as parameter types of the eta-expanded closure
1466+
0
1467+
else defn.functionArity(pt)
14641468
else if (pt eq AnyFunctionProto) wtp.paramTypes.length
14651469
else -1
1466-
if (arity >= 0 && !tree.symbol.isConstructor)
1470+
if (arity >= 0 && !tree.symbol.isConstructor) {
14671471
typed(etaExpand(tree, wtp, arity), pt)
1468-
else if (wtp.paramTypes.isEmpty)
1472+
} else if (wtp.paramTypes.isEmpty)
14691473
adaptInterpolated(tpd.Apply(tree, Nil), pt, EmptyTree)
14701474
else if (wtp.isImplicit)
14711475
err.typeMismatch(tree, pt)

tests/pos/i1036.scala

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

0 commit comments

Comments
 (0)