Open exelotl opened 3 years ago
Workaround: Depending on the use case, you may be able to use a helper proc defined before the term-rewriting macro, to which the rules of the macro don't apply:
# test 1
# ------
proc get(x: int): int = x
proc getFinal(x: int): int {.inline.} =
get(x)
template t{get(a)}(a: int): int =
getFinal(a) + 1
echo get(0)
# test 2
# ------
var x: int
proc asgnFinal[T](a: var T, b: T) {.inline.} =
a = b
template asgn{a = b}(a: int{lvalue}, b: int) =
asgnFinal(a, b + 1)
x = 10
echo x
Output:
1
11
While playing with term rewriting macros, I found that the
{.noRewrite.}
pragma doesn't behave as expected at all.Example
Current output
Tested from Nim 0.20.0 to 1.4.2:
Expected output
Additional information
The output on Nim 0.19.6 is different, test 2 gives the correct result: