@@ -121,23 +121,26 @@ power(expr, 10)
121121```
122122
123123Parameters of inline methods can have an ` inline ` modifier as well. This means
124- that actual arguments to these parameters will be inlined in the body of the ` inline def ` .
125- ` inline ` parameter have call semantics equivalent to by-name parameters but allows for duplication
126- of the code in the argument. It is usualy useful constant values need to be propagated to allow
127- further optimizations/reductions.
124+ that actual arguments to these parameters will be inlined in the body of the
125+ ` inline def ` . ` inline ` parameters have call semantics equivalent to by-name parameters
126+ but allow for duplication of the code in the argument. It is usually useful when constant
127+ values need to be propagated to allow further optimizations/reductions.
128128
129129The following example shows the difference in translation between by-value, by-name and ` inline `
130130parameters:
131131
132132``` scala
133- inline def sumTwice (a : Int , b : => Int , inline c : Int ) = a + a + b + b + c + c
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}" )
134136
135- sumTwice(f (), g(), h())
137+ funkyAssertEquals(computeActual (), f() + g(), h() + i() - j ())
136138// translates to
137139//
138- // val a = f()
139- // def b = g()
140- // a + a + b + b + h() + h()
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()}")
141144```
142145
143146### Relationship to @inline
0 commit comments