Skip to content

Commit

Permalink
fixes #12334; keeps nkHiddenStdConv for cstring conversions (#23216)
Browse files Browse the repository at this point in the history
fixes #12334

`nkHiddenStdConv` shouldn't be removed if the sources aren't literals,
viz. constant symbols.

(cherry picked from commit 3fb46fa)
  • Loading branch information
ringabout authored and narimiran committed Apr 19, 2024
1 parent 3166c6a commit 2d4c59d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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
Expand Down
10 changes: 10 additions & 0 deletions tests/vm/tconst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2d4c59d

Please sign in to comment.