Skip to content

Commit 7cbbd8f

Browse files
authored
doc(inline): show inline can result in larger code
1 parent 57667a0 commit 7cbbd8f

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,17 @@ The following example shows the difference in translation between by-value, by-n
130130
parameters:
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

0 commit comments

Comments
 (0)