Skip to content

Commit 1a9cdab

Browse files
committed
Always do eta expansion if arity >= 1
Implements another part of #2570
1 parent e91afd4 commit 1a9cdab

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,8 +2010,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
20102010
// prioritize method parameter types as parameter types of the eta-expanded closure
20112011
0
20122012
else defn.functionArity(ptNorm)
2013-
else if (pt eq AnyFunctionProto) wtp.paramInfos.length
2014-
else -1
2013+
else {
2014+
val nparams = wtp.paramInfos.length
2015+
if (nparams > 0 || pt.eq(AnyFunctionProto)) nparams
2016+
else -1 // no eta expansion in this case
2017+
}
2018+
20152019
if (arity >= 0 && !tree.symbol.isConstructor)
20162020
typed(etaExpand(tree, wtp, arity), pt)
20172021
else if (wtp.paramInfos.isEmpty)

tests/pos/i2570.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ object Test {
2121
def sum2(x: Int, ys: Int*) = (x /: ys)(_ + _)
2222
val h1: ((Int, Seq[Int]) => Int) = sum2
2323

24-
// Not yet:
25-
// val h1 = repeat
26-
// val h2: (String, Int, Int) = h1
27-
// val h3 = sum
28-
// val h4: (Int, => Int) = h3
24+
val h3 = repeat
25+
val h4: ((String, Int, Int) => String) = h3
26+
val h5 = sum
27+
val h6: ((Int, => Int) => Int) = h5
28+
29+
class A
30+
class B
31+
class C
32+
implicit object b extends B
33+
34+
def foo(x: A)(implicit bla: B): C = ???
35+
36+
val h7 = foo
37+
val h8: A => C = h7
2938
}

0 commit comments

Comments
 (0)