mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
don't update const symbol on const section re-sems (#22609)
fixes #19849
This commit is contained in:
@@ -867,9 +867,13 @@ proc semConst(c: PContext, n: PNode): PNode =
|
||||
styleCheckDef(c, v)
|
||||
onDef(a[j].info, v)
|
||||
|
||||
setVarType(c, v, typ)
|
||||
when false:
|
||||
v.ast = def # no need to copy
|
||||
var fillSymbol = true
|
||||
if v.typ != nil:
|
||||
# symbol already has type and probably value
|
||||
# don't mutate
|
||||
fillSymbol = false
|
||||
else:
|
||||
setVarType(c, v, typ)
|
||||
b = newNodeI(nkConstDef, a.info)
|
||||
if importantComments(c.config): b.comment = a.comment
|
||||
# postfix not generated here (to generate, get rid of it in transf)
|
||||
@@ -882,8 +886,9 @@ proc semConst(c: PContext, n: PNode): PNode =
|
||||
b.add newSymNode(v)
|
||||
b.add a[1]
|
||||
b.add copyTree(def)
|
||||
v.ast = b
|
||||
addToVarSection(c, result, n, b)
|
||||
if fillSymbol:
|
||||
v.ast = b
|
||||
addToVarSection(c, result, n, b)
|
||||
dec c.inStaticContext
|
||||
|
||||
include semfields
|
||||
|
||||
10
tests/vm/tconstresem.nim
Normal file
10
tests/vm/tconstresem.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
block: # issue #19849
|
||||
type
|
||||
Vec2[T] = object
|
||||
x, y: T
|
||||
Vec2i = Vec2[int]
|
||||
template getX(p: Vec2i): int = p.x
|
||||
let x = getX:
|
||||
const t = Vec2i(x: 1, y: 2)
|
||||
t
|
||||
doAssert x == 1
|
||||
Reference in New Issue
Block a user