* 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>
This commit is contained in:
parent
fc8bfd781a
commit
a228e331f3
2 changed files with 19 additions and 1 deletions
|
|
@ -1596,11 +1596,20 @@ proc genTypeLit(c: PCtx; t: PType; dest: var TDest) =
|
||||||
n.typ = t
|
n.typ = t
|
||||||
genLit(c, n, dest)
|
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.} =
|
proc importcCond*(c: PCtx; s: PSym): bool {.inline.} =
|
||||||
## return true to importc `s`, false to execute its body instead (refs #8405)
|
## return true to importc `s`, false to execute its body instead (refs #8405)
|
||||||
if sfImportc in s.flags:
|
if sfImportc in s.flags:
|
||||||
if s.kind in routineKinds:
|
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) =
|
proc importcSym(c: PCtx; info: TLineInfo; s: PSym) =
|
||||||
when hasFFI:
|
when hasFFI:
|
||||||
|
|
|
||||||
9
tests/vm/t17121.nim
Normal file
9
tests/vm/t17121.nim
Normal file
|
|
@ -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")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue