diff options
author | quantimnot <54247259+quantimnot@users.noreply.github.com> | 2021-03-05 08:41:33 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-05 14:41:33 +0100 |
commit | b2b23d723afde51d54a63d1c19e0ae04d6d826c7 (patch) | |
tree | 72e8f02d038bf18100ce99b31cb8318f86be8229 /lib/core | |
parent | 171b03c3861e1bcd722303a42b7ad11b14635215 (diff) | |
download | Nim-b2b23d723afde51d54a63d1c19e0ae04d6d826c7.tar.gz |
Fix macros.quote custom op symbol interpolation. (#17256)
Provides a workaround/fix for #7589. https://github.com/nim-lang/Nim/issues/7589 Updated docs and tutorial to reflect change. Updated runnableExamples to include an example. Co-authored-by: name <name@example.com>
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/macros.nim | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index d5925e1ff..491235d8b 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -555,6 +555,9 @@ proc quote*(bl: typed, op = "``"): NimNode {.magic: "QuoteAst", noSideEffect.} = ## operator may be obtained by escaping it (by prefixing it with itself) when used ## as a unary operator: ## e.g. `@` is escaped as `@@`, `&%` is escaped as `&%&%` and so on; see examples. + ## + ## A custom operator interpolation needs accent quoted (``) whenever it resolves + ## to a symbol. runnableExamples: macro check(ex: untyped) = # this is a simplified version of the check macro from the @@ -593,10 +596,11 @@ proc quote*(bl: typed, op = "``"): NimNode {.magic: "QuoteAst", noSideEffect.} = runnableExamples: # custom `op` var destroyCalled = false - macro bar() = + macro bar(ident) = var x = 1.5 result = quote("@") do: type Foo = object + let `@ident` = 0 # custom op interpolated symbols need quoted (``) proc `=destroy`(a: var Foo) = doAssert @x == 1.5 doAssert compiles(@x == 1.5) @@ -607,7 +611,7 @@ proc quote*(bl: typed, op = "``"): NimNode {.magic: "QuoteAst", noSideEffect.} = destroyCalled = true block: let a = Foo() - bar() + bar(someident) doAssert destroyCalled proc `&%`(x: int): int = 1 |