diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2022-11-06 22:25:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-06 22:25:55 +0800 |
commit | a228e331f30def00d4369d4e792c7454963d8c4e (patch) | |
tree | c71f290614fb8c65c64a17d6780b1cd85ccc412a | |
parent | fc8bfd781a68d3d3efdf713fa2c92c440c7783a2 (diff) | |
download | Nim-a228e331f30def00d4369d4e792c7454963d8c4e.tar.gz |
fixes regression #17121; adding doc comment in importc proc makes it silently noop at CT (#20766)
* fixes regression #17121; adding doc comment in importc proc makes it silently noop at CT * Update compiler/vmgen.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | compiler/vmgen.nim | 11 | ||||
-rw-r--r-- | tests/vm/t17121.nim | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 9680fe9ba..1fdfea7c4 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1596,11 +1596,20 @@ proc genTypeLit(c: PCtx; t: PType; dest: var TDest) = n.typ = t genLit(c, n, dest) +proc isEmptyBody(n: PNode): bool = + case n.kind + of nkStmtList: + for i in 0..<n.len: + if not isEmptyBody(n[i]): return false + result = true + else: + result = n.kind in {nkCommentStmt, nkEmpty} + proc importcCond*(c: PCtx; s: PSym): bool {.inline.} = ## return true to importc `s`, false to execute its body instead (refs #8405) if sfImportc in s.flags: if s.kind in routineKinds: - return getBody(c.graph, s).kind == nkEmpty + return isEmptyBody(getBody(c.graph, s)) proc importcSym(c: PCtx; info: TLineInfo; s: PSym) = when hasFFI: diff --git a/tests/vm/t17121.nim b/tests/vm/t17121.nim new file mode 100644 index 000000000..bf2d6423f --- /dev/null +++ b/tests/vm/t17121.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "cannot 'importc' variable at compile time; c_printf" +""" + +proc c_printf*(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs, discardable.} = + ## foo bar + runnableExamples: discard +static: + let a = c_printf("abc\n") |