Skip to content

Commit c0f7f1f

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Avoid eta-reduction of (..., f: T => R, ...) => f.apply(..) into f
Fixes #19962 [Cherry-picked e59335f]
1 parent 19d673b commit c0f7f1f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

compiler/src/dotty/tools/dotc/transform/EtaReduce.scala

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class EtaReduce extends MiniPhase:
4343
arg.isInstanceOf[Ident] && arg.symbol == param.symbol)
4444
&& isPurePath(fn)
4545
&& fn.tpe <:< tree.tpe
46+
&& !(fn.symbol.is(Flags.Param) && fn.symbol.owner == mdef.symbol) // Do not eta-educe `(..., f: T => R, ...) => f.apply(..)` into `f`
4647
&& defn.isFunctionClass(fn.tpe.widen.typeSymbol) =>
4748
report.log(i"eta reducing $tree --> $fn")
4849
fn

tests/pos/i19962.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def selfie0: (AnyRef => AnyRef) => AnyRef = (f:AnyRef => AnyRef) => f(f)
2+
def selfie1: Any = (f: Any => Any) => f(f)
3+
def selfie2: Any = (f: (Any, Any) => Any, g: (Any, Any) => Any) => f(f, g)
4+
def selfie3: Any = (f: (Any, Any) => Any, g: (Any, Any) => Any) => g(f, g)

0 commit comments

Comments
 (0)