fixes #23295; don't expand constants for complex structures (#23297)

fixes #23295

(cherry picked from commit 39f2df1972)
This commit is contained in:
ringabout
2024-02-20 14:31:58 +08:00
committed by narimiran
parent 4e1b5ee702
commit 0c426e7875
2 changed files with 19 additions and 2 deletions

View File

@@ -213,8 +213,7 @@ proc stupidStmtListExpr*(n: PNode): bool =
proc dontInlineConstant*(orig, cnst: PNode): bool {.inline.} =
# symbols that expand to a complex constant (array, etc.) should not be
# inlined, unless it's the empty array:
result = orig.kind != cnst.kind and
cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket, nkObjConstr} and
result = cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket, nkObjConstr} and
cnst.len > ord(cnst.kind == nkObjConstr)
proc isRunnableExamples*(n: PNode): bool =

View File

@@ -0,0 +1,18 @@
# This is a sample code, the first echo statement prints out the error
type
A = object
case w: uint8
of 1:
n: int
else:
other: string
const
a = A(w: 1, n: 5)
proc foo =
let c = [a]
doAssert c[0].n == 5
foo()