Skip to content

Commit 55bb60a

Browse files
ringaboutnarimiran
authored andcommitted
fixes #22947; static integers in quote do [backport] (#22948)
fixes #22947 (cherry picked from commit 09ea1b1)
1 parent ef8b831 commit 55bb60a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/semexprs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
22392239
for i in 1..<ids.len:
22402240
let exp = semExprWithType(c, quotes[i+1], {})
22412241
let typ = exp.typ
2242-
if tfTriggersCompileTime notin typ.flags and exp.kind == nkSym and exp.sym.kind notin routineKinds + {skType}:
2242+
if tfTriggersCompileTime notin typ.flags and typ.kind != tyStatic and exp.kind == nkSym and exp.sym.kind notin routineKinds + {skType}:
22432243
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[i], newNodeIT(nkType, n.info, typ), c.graph.emptyNode)
22442244
else:
22452245
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[i], getSysSym(c.graph, n.info, "typed").newSymNode, c.graph.emptyNode)

tests/stdlib/tmacros.nim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,16 @@ block:
334334
`hello`(12, type(x))
335335
336336
main()
337+
338+
block: # bug #22947
339+
macro bar[N: static int](a: var array[N, int]) =
340+
result = quote do:
341+
for i in 0 ..< `N`:
342+
`a`[i] = i
343+
344+
func foo[N: static int](a: var array[N, int]) =
345+
bar(a)
346+
347+
348+
var a: array[4, int]
349+
foo(a)

0 commit comments

Comments
 (0)