fixes #12334; keeps nkHiddenStdConv for cstring conversions (#23216)

fixes #12334

`nkHiddenStdConv` shouldn't be removed if the sources aren't literals,
viz. constant symbols.
This commit is contained in:
ringabout
2024-01-19 04:31:49 +08:00
committed by GitHub
parent 527d1e1977
commit 3fb46fac32
2 changed files with 12 additions and 0 deletions

View File

@@ -339,6 +339,8 @@ proc fitRemoveHiddenConv(c: PContext, typ: PType, n: PNode): PNode =
result.typ = typ
if not floatRangeCheck(result.floatVal, typ):
localError(c.config, n.info, errFloatToString % [$result.floatVal, typeToString(typ)])
elif r1.kind == nkSym and typ.skipTypes(abstractRange).kind == tyCstring:
discard "keep nkHiddenStdConv for cstring conversions"
else:
changeType(c, r1, typ, check=true)
result = r1

View File

@@ -42,6 +42,16 @@ template main() =
discard (x, increment, a)
mytemp()
block: # bug #12334
block:
const b: cstring = "foo"
var c = b
doAssert c == "foo"
block:
const a = "foo"
const b: cstring = a
var c = b
doAssert c == "foo"
static: main()