Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid eta-reduction of (..., f: T => R, ...) => f.apply(..) into f #19966

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading