Fix semfold handling of {.str/int/bool-define.} (#13964)
This commit is contained in:
parent
40b64ccd7b
commit
255698deee
2 changed files with 18 additions and 0 deletions
|
|
@ -549,9 +549,13 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
||||||
localError(g.config, s.info,
|
localError(g.config, s.info,
|
||||||
"{.intdefine.} const was set to an invalid integer: '" &
|
"{.intdefine.} const was set to an invalid integer: '" &
|
||||||
g.config.symbols[s.name.s] & "'")
|
g.config.symbols[s.name.s] & "'")
|
||||||
|
else:
|
||||||
|
result = copyTree(s.ast)
|
||||||
of mStrDefine:
|
of mStrDefine:
|
||||||
if isDefined(g.config, s.name.s):
|
if isDefined(g.config, s.name.s):
|
||||||
result = newStrNodeT(g.config.symbols[s.name.s], n, g)
|
result = newStrNodeT(g.config.symbols[s.name.s], n, g)
|
||||||
|
else:
|
||||||
|
result = copyTree(s.ast)
|
||||||
of mBoolDefine:
|
of mBoolDefine:
|
||||||
if isDefined(g.config, s.name.s):
|
if isDefined(g.config, s.name.s):
|
||||||
try:
|
try:
|
||||||
|
|
@ -560,6 +564,8 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
||||||
localError(g.config, s.info,
|
localError(g.config, s.info,
|
||||||
"{.booldefine.} const was set to an invalid bool: '" &
|
"{.booldefine.} const was set to an invalid bool: '" &
|
||||||
g.config.symbols[s.name.s] & "'")
|
g.config.symbols[s.name.s] & "'")
|
||||||
|
else:
|
||||||
|
result = copyTree(s.ast)
|
||||||
else:
|
else:
|
||||||
result = copyTree(s.ast)
|
result = copyTree(s.ast)
|
||||||
of skProc, skFunc, skMethod:
|
of skProc, skFunc, skMethod:
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,15 @@ doAssert booldef
|
||||||
doAssert not booldef2
|
doAssert not booldef2
|
||||||
doAssert intdef == 2
|
doAssert intdef == 2
|
||||||
doAssert strdef == "foobar"
|
doAssert strdef == "foobar"
|
||||||
|
|
||||||
|
# Intentionally not defined from command line
|
||||||
|
const booldef3 {.booldefine.} = true
|
||||||
|
const intdef2 {.intdefine.} = 1
|
||||||
|
const strdef2 {.strdefine.} = "abc"
|
||||||
|
type T = object
|
||||||
|
when booldef3:
|
||||||
|
field1: int
|
||||||
|
when intdef2 == 1:
|
||||||
|
field2: int
|
||||||
|
when strdef2 == "abc":
|
||||||
|
field3: int
|
||||||
Loading…
Add table
Add a link
Reference in a new issue