Skip to content

Commit

Permalink
Backport "Avoid eta-reduction of `(..., f: T => R, ...) => f.apply(..…
Browse files Browse the repository at this point in the history
…)` into `f`" to LTS (#20996)

Backports #19966 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 4, 2024
2 parents 6ba333b + 971c5be commit 597ff96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/EtaReduce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class EtaReduce extends MiniPhase:
arg.isInstanceOf[Ident] && arg.symbol == param.symbol)
&& isPurePath(fn)
&& fn.tpe <:< tree.tpe
&& !(fn.symbol.is(Flags.Param) && fn.symbol.owner == mdef.symbol) // Do not eta-educe `(..., f: T => R, ...) => f.apply(..)` into `f`
&& defn.isFunctionClass(fn.tpe.widen.typeSymbol) =>
report.log(i"eta reducing $tree --> $fn")
fn
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i19962.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def selfie0: (AnyRef => AnyRef) => AnyRef = (f:AnyRef => AnyRef) => f(f)
def selfie1: Any = (f: Any => Any) => f(f)
def selfie2: Any = (f: (Any, Any) => Any, g: (Any, Any) => Any) => f(f, g)
def selfie3: Any = (f: (Any, Any) => Any, g: (Any, Any) => Any) => g(f, g)

0 comments on commit 597ff96

Please # to comment.