Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/trees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,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 =
Expand Down
18 changes: 18 additions & 0 deletions tests/objvariant/tconstobjvariant.nim
Original file line number Diff line number Diff line change
@@ -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()
Loading