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:
48
48
fn
49
49
case TypeApply (Select (qual, _), _) if rhs.symbol.isTypeCast && rhs.span.isSynthetic =>
50
50
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)
51
55
case _ =>
52
56
tree
53
57
Original file line number Diff line number Diff line change @@ -59,6 +59,25 @@ class RegressionTestScala3 {
59
59
assertEquals(0L , Foo .bar().x)
60
60
assertEquals(5L , Foo .bar(5L ).x)
61
61
}
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
+ }
62
81
}
63
82
64
83
object RegressionTestScala3 {
You can’t perform that action at this time.
0 commit comments