Skip to content

[TODO] VM: allow const ref objects #13082

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

Closed
wants to merge 2 commits into from
Closed
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/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
elif kind in {skVar, skLet}:
result = t[1]
of tyRef:
if kind == skConst: result = t
else: result = typeAllowedAux(marker, t.lastSon, kind, flags+{taHeap})
result = typeAllowedAux(marker, t.lastSon, kind, flags+{taHeap})
of tyPtr:
result = typeAllowedAux(marker, t.lastSon, kind, flags+{taHeap})
of tySet:
Expand Down
21 changes: 21 additions & 0 deletions tests/vm/tconstrefs.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import std/json

block: # case ref objects
const j = parseJson(""" {"x1":12,"x2":"asdf","x3":[1,2]} """)
const x1 = j["x1"].getInt
const x2 = j["x3"].to(seq[int])
when false:
# pending https://github.com/nim-lang/Nim/issues/13081
echo j["x1"].getInt

doAssert x1 == 12
doAssert x2 == @[1, 2]

block: # case objects
type Foo = ref object
x1: int
x2: string
x3: seq[string]
const j1 = Foo(x1: 12, x2: "asdf", x3: @["foo", "bar"])
doAssert j1[] == Foo(x1: 12, x2: "asdf", x3: @["foo", "bar"])[]
doAssert $j1[] == """(x1: 12, x2: "asdf", x3: @["foo", "bar"])"""