Skip to content

Commit 0ceb710

Browse files
committed
Upadate docs
1 parent e5c5aba commit 0ceb710

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

docs/docs/reference/principled-meta-programming.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ statically known exponent:
383383
private def powerCode(n: Int, x: Expr[Double]): Expr[Double] =
384384
if (n == 0) '(1.0)
385385
else if (n == 1) x
386-
else if (n % 2 == 0) '{ { val y = ~x * ~x; ~powerCode(n / 2, '(y)) } }
386+
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode(n / 2, '(y)) }
387387
else '{ ~x * ~powerCode(n - 1, x) }
388388

389389
The reference to `n` as an argument in `~powerCode(n, '(x))` is not
@@ -436,7 +436,8 @@ we currently impose the following restrictions on the use of splices.
436436
1. A top-level splice must appear in an inline function (turning that function
437437
into a macro)
438438

439-
2. The splice must call a previously compiled method.
439+
2. The splice must call a previously compiled (previous to the call of the inline definition)
440+
static method passing quoted arguments, constant arguments or inline arguments.
440441

441442
3. Splices inside splices (but no intervening quotes) are not allowed.
442443

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted._
2+
3+
object Macros {
4+
def assertImpl(expr: Expr[Boolean]) = '{ println(~expr) }
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
object Test {
3+
4+
inline def assert2(expr: => Boolean): Unit = ~Macros.assertImpl('(expr))
5+
6+
def main(args: Array[String]): Unit = {
7+
val x = 1
8+
assert2(x != 0)
9+
assert2(x == 0)
10+
}
11+
}

0 commit comments

Comments
 (0)