File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
docs/docs/reference/metaprogramming Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -130,20 +130,17 @@ The following example shows the difference in translation between by-value, by-n
130130parameters:
131131
132132``` scala
133- inline def specialSum (a : Int , b : => Int , inline c : Int ) =
134- (if (a < 2 ) a else 0 ) +
135- (if (a < 2 ) b + b else 0 ) +
136- (if (a < 2 ) c + c else 0 )
137- }
133+ inline def funkyAssertEquals (actual : Double , expected : => Double , inline delta : Double ): Unit =
134+ if (actual - expected).abs > delta then
135+ throw new AssertionError (s " difference between ${expected} and ${actual} was larger than ${delta}" )
138136
139- specialSum(f (), g(), h())
137+ funkyAssertEquals(computeActual (), f() + g(), h() + i() - j ())
140138// translates to
141139//
142- // val a = f()
143- // lazy val b = g()
144- // (if(a < 2) a else 0) +
145- // (if(a < 2) b + b else 0) +
146- // (if(a < 2) h() + h() else 0)
140+ // val actual = computeActual()
141+ // def expected = f() + g()
142+ // if (actual - expected).abs > h() + i() - j() then
143+ // throw new AssertionError(s"difference between ${expected} and ${actual} was larger than ${h() + i() - j()}")
147144```
148145
149146### Relationship to @inline
You can’t perform that action at this time.
0 commit comments