@@ -121,23 +121,26 @@ power(expr, 10)
121
121
```
122
122
123
123
Parameters 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.
128
128
129
129
The following example shows the difference in translation between by-value, by-name and ` inline `
130
130
parameters:
131
131
132
132
``` 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}" )
134
136
135
- sumTwice(f (), g(), h())
137
+ funkyAssertEquals(computeActual (), f() + g(), h() + i() - j ())
136
138
// translates to
137
139
//
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()}")
141
144
```
142
145
143
146
### Relationship to @inline
0 commit comments