Skip to content

Commit fedd695

Browse files
authored
Merge pull request #9046 from LemonBoy/fix-9043
Fix for VM codegen with static[T] types
2 parents 179791a + fb54f39 commit fedd695

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

compiler/vmgen.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
15291529

15301530
template needsRegLoad(): untyped =
15311531
{gfNode, gfNodeAddr} * flags == {} and
1532-
fitsRegister(n.typ.skipTypes({tyVar, tyLent}))
1532+
fitsRegister(n.typ.skipTypes({tyVar, tyLent, tyStatic}))
15331533

15341534
proc genArrAccess2(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
15351535
flags: TGenFlags) =
@@ -1590,7 +1590,7 @@ proc getNullValueAux(obj: PNode, result: PNode; conf: ConfigRef) =
15901590
else: globalError(conf, result.info, "cannot create null element for: " & $obj)
15911591

15921592
proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
1593-
var t = skipTypes(typ, abstractRange-{tyTypeDesc})
1593+
var t = skipTypes(typ, abstractRange+{tyStatic}-{tyTypeDesc})
15941594
case t.kind
15951595
of tyBool, tyEnum, tyChar, tyInt..tyInt64:
15961596
result = newNodeIT(nkIntLit, info, t)
@@ -1602,7 +1602,7 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
16021602
result = newNodeIT(nkStrLit, info, t)
16031603
result.strVal = ""
16041604
of tyVar, tyLent, tyPointer, tyPtr, tyExpr,
1605-
tyStmt, tyTypeDesc, tyStatic, tyRef, tyNil:
1605+
tyStmt, tyTypeDesc, tyRef, tyNil:
16061606
result = newNodeIT(nkNilLit, info, t)
16071607
of tyProc:
16081608
if t.callConv != ccClosure:

tests/vm/t9043.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
discard """
2+
nimout: "(Field0: 2, Field1: 2, Field2: 2, Field3: 2)"
3+
"""
4+
5+
proc foo[N: static[int]](dims: array[N, int])=
6+
const N1 = N
7+
const N2 = dims.len
8+
static: echo (N, dims.len, N1, N2)
9+
10+
foo([1, 2])

0 commit comments

Comments
 (0)