fixes #22947; static integers in quote do [backport] (#22948)

fixes #22947

(cherry picked from commit 09ea1b168f)
This commit is contained in:
ringabout
2023-11-18 16:40:28 +08:00
committed by narimiran
parent ef8b8317ff
commit 55bb60a56b
2 changed files with 14 additions and 1 deletions

View File

@@ -2239,7 +2239,7 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
for i in 1..<ids.len:
let exp = semExprWithType(c, quotes[i+1], {})
let typ = exp.typ
if tfTriggersCompileTime notin typ.flags and exp.kind == nkSym and exp.sym.kind notin routineKinds + {skType}:
if tfTriggersCompileTime notin typ.flags and typ.kind != tyStatic and exp.kind == nkSym and exp.sym.kind notin routineKinds + {skType}:
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[i], newNodeIT(nkType, n.info, typ), c.graph.emptyNode)
else:
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[i], getSysSym(c.graph, n.info, "typed").newSymNode, c.graph.emptyNode)

View File

@@ -334,3 +334,16 @@ block:
`hello`(12, type(x))
main()
block: # bug #22947
macro bar[N: static int](a: var array[N, int]) =
result = quote do:
for i in 0 ..< `N`:
`a`[i] = i
func foo[N: static int](a: var array[N, int]) =
bar(a)
var a: array[4, int]
foo(a)