mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 22:35:24 +00:00
progress: skips the current routine scopes
This commit is contained in:
@@ -2450,9 +2450,17 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
|
||||
# don't allow templates to capture syms without backticks
|
||||
let oldScope = c.currentScope
|
||||
# c.currentScope = PScope(parent: nil, symbols: initStrTable(), depthLevel: 0)
|
||||
# TODO: allows toplevel syms to be captured for backwards compatibility
|
||||
# perhaps `{.dirty.}` can be used for `dummyTemplate`
|
||||
c.currentScope = c.topLevelScope
|
||||
if c.p.owner.kind in routineKinds:
|
||||
# skips the current routine scopes
|
||||
block exitLabel:
|
||||
while c.currentScope != nil:
|
||||
c.currentScope = c.currentScope.parent
|
||||
block continueLabel:
|
||||
for s in items(c.currentScope.symbols):
|
||||
if s.owner != c.p.owner:
|
||||
break exitLabel
|
||||
else:
|
||||
break continueLabel
|
||||
var tmpl = semTemplateDef(c, dummyTemplate)
|
||||
c.currentScope = oldScope
|
||||
quotes[0] = tmpl[namePos]
|
||||
|
||||
@@ -163,9 +163,9 @@ template main =
|
||||
doAssert fn3() == "[[-12]]"
|
||||
|
||||
block: # bug 9 from https://github.com/nim-lang/Nim/pull/17020#issuecomment-803193947
|
||||
func wrap1(a: string): string = "{" & a & "}"
|
||||
func `'wrap3`(a: string): string = "{" & a & "}"
|
||||
macro metawrap(): untyped =
|
||||
func wrap1(a: string): string = "{" & a & "}"
|
||||
func `'wrap3`(a: string): string = "{" & a & "}"
|
||||
result = quote do:
|
||||
let a1 {.inject.} = wrap1"-128"
|
||||
let a2 {.inject.} = -128'wrap3
|
||||
|
||||
@@ -332,7 +332,7 @@ block:
|
||||
macro main =
|
||||
let x = 12
|
||||
result = quote do:
|
||||
`hello`(12, type(x))
|
||||
`hello`(12, type(`x`))
|
||||
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user