Skip to content

Commit 597ff96

Browse files
Backport "Avoid eta-reduction of (..., f: T => R, ...) => f.apply(..) into f" to LTS (#20996)
Backports #19966 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 6ba333b + 971c5be commit 597ff96

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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)