Skip to content

Commit d32761c

Browse files
committed
Avoid eta-reduction on f => f(f)
Fixes #19962
1 parent 4859415 commit d32761c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class EtaReduce extends MiniPhase:
4040
case Apply(Select(fn, name), args)
4141
if (name == nme.apply || defn.FunctionSpecializedApplyNames.contains(name))
4242
&& mdef.paramss.head.corresponds(args)((param, arg) =>
43-
arg.isInstanceOf[Ident] && arg.symbol == param.symbol)
43+
arg.isInstanceOf[Ident] && arg.symbol == param.symbol && arg.symbol != fn.symbol)
4444
&& isPurePath(fn)
4545
&& fn.tpe <:< tree.tpe
4646
&& defn.isFunctionClass(fn.tpe.widen.typeSymbol) =>

tests/pos/i19962.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def selfie0: (AnyRef => AnyRef) => AnyRef = (f:AnyRef => AnyRef) => f(f)
2+
def selfie1: Any = (f: Any => Any) => f(f)

0 commit comments

Comments
 (0)