File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
compiler/src/dotty/tools/dotc/transform
tests/sjs-junit/test/org/scalajs/testsuite/compiler Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ class EtaReduce extends MiniPhase:
4848 fn
4949 case TypeApply (Select (qual, _), _) if rhs.symbol.isTypeCast && rhs.span.isSynthetic =>
5050 tryReduce(mdef, qual)
51+ case Apply (_, arg :: Nil ) if Erasure .Boxing .isUnbox(rhs.symbol) && rhs.span.isSynthetic =>
52+ tryReduce(mdef, arg)
53+ case Block (call :: Nil , unit @ Literal (Constants .Constant (()))) if unit.span.isSynthetic =>
54+ tryReduce(mdef, call)
5155 case _ =>
5256 tree
5357
Original file line number Diff line number Diff line change @@ -59,6 +59,25 @@ class RegressionTestScala3 {
5959 assertEquals(0L , Foo .bar().x)
6060 assertEquals(5L , Foo .bar(5L ).x)
6161 }
62+
63+ @ Test def etaReduceIssue15494 (): Unit = {
64+ // Also known as tests/run/i14623.scala for Scala/JVM
65+
66+ object Thunk {
67+ private [this ] val impl =
68+ ((x : Any ) => x).asInstanceOf [(=> Any ) => Function0 [Any ]]
69+
70+ def asFunction0 [A ](thunk : => A ): Function0 [A ] = impl(thunk).asInstanceOf [Function0 [A ]]
71+ }
72+
73+ var i = 0
74+ val f1 = { () => i += 1 ; " " }
75+ assertSame(f1, Thunk .asFunction0(f1()))
76+ val f2 = { () => i += 1 ; i }
77+ assertSame(f2, Thunk .asFunction0(f2()))
78+ val f3 = { () => i += 1 }
79+ assertSame(f3, Thunk .asFunction0(f3()))
80+ }
6281}
6382
6483object RegressionTestScala3 {
You can’t perform that action at this time.
0 commit comments