diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-03-02 00:18:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-01 17:18:09 +0100 |
commit | 1b1412f3d148b02fb553f37d84505745cf3fb435 (patch) | |
tree | 1a9776e5fe1c8a4c6988578f5b71bb6cf8b348aa /compiler | |
parent | c4dd0c43016faadbdaaddb2decf95dc881eb772e (diff) | |
download | Nim-1b1412f3d148b02fb553f37d84505745cf3fb435.tar.gz |
fixes #10938; fixes #13312; fixes #13918; fixes #20985; always initializes global variables with null values in VM (#21351)
* fixes #10938; always initialize global variable in VM * fixes importc vars * there is a pre-existing issue regarding closure types in the VM * add tests
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/vmgen.nim | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index bdf7b679e..be7938e53 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1909,6 +1909,18 @@ proc genVarSection(c: PCtx; n: PNode) = c.genAdditionalCopy(a[2], opcWrDeref, tmp, 0, val) c.freeTemp(val) c.freeTemp(tmp) + elif not importcCondVar(s) and not (s.typ.kind == tyProc and s.typ.callConv == ccClosure): # fixes #10938 + # there is a pre-existing issue with closure types in VM + # if `(var s: proc () = default(proc ()); doAssert s == nil)` works for you; + # you might remove the second condition. + # the problem is that closure types are tuples in VM, but the types of its children + # shouldn't have the same type as closure types. + let tmp = c.genx(a[0], {gfNodeAddr}) + let sa = getNullValue(s.typ, a.info, c.config) + let val = c.genx(sa) + c.genAdditionalCopy(sa, opcWrDeref, tmp, 0, val) + c.freeTemp(val) + c.freeTemp(tmp) else: setSlot(c, s) if a[2].kind == nkEmpty: |