diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 008eab0fdbb7..b1e4bb48a97f 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1460,7 +1460,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } case wtp: MethodType if !pt.isInstanceOf[SingletonType] => val arity = - if (defn.isFunctionType(pt)) defn.functionArity(pt) + if (defn.isFunctionType(pt)) + if (!isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none)) + // if method type is fully defined, but expected type is not, + // prioritize method parameter types as parameter types of the eta-expanded closure + 0 + else defn.functionArity(pt) else if (pt eq AnyFunctionProto) wtp.paramTypes.length else -1 if (arity >= 0 && !tree.symbol.isConstructor) diff --git a/tests/pos/i1036.scala b/tests/pos/i1036.scala new file mode 100644 index 000000000000..6110f9681a17 --- /dev/null +++ b/tests/pos/i1036.scala @@ -0,0 +1,12 @@ +object Test { + def second[sA, sB <: sA](foo: sA, bar: sB): sB = bar + def third[A, B >: A](foo: A, bar: B): B = bar + def expectString(s: String) = s + + def test = { + val x = second(Set.empty[String], Set.empty) + x map expectString + second(Set.empty[String], Set.empty) map expectString + third(Set.empty[String], Set.empty) map expectString + } +}