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 #20048; fixes #15746; don't sink object fields if it's of openarray type #23608

Merged
merged 5 commits into from
Jun 15, 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: 2 additions & 1 deletion compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode; tmpFlags = {sfSing
for i in 1..<n.len:
if n[i].kind == nkExprColonExpr:
let field = lookupFieldAgain(t, n[i][0].sym)
if field != nil and sfCursor in field.flags:
if field != nil and (sfCursor in field.flags or field.typ.kind in {tyOpenArray, tyVarargs}):
# don't sink fields with openarray types
result[i][1] = p(n[i][1], c, s, normal)
else:
result[i][1] = p(n[i][1], c, s, m)
Expand Down
10 changes: 10 additions & 0 deletions tests/views/tviews1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,13 @@ proc bug22597 = # bug #22597
doAssert i == 1

bug22597()

block: # bug #20048
type
Test = object
tokens: openArray[string]

func init(Self: typedesc[Test], tokens: openArray[string]): Self = Self(tokens: tokens)

let data = Test.init(["123"])
doAssert @(data.tokens) == @["123"]
12 changes: 12 additions & 0 deletions tests/views/tviews2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ block: # bug #16671

f()

block: # bug #15746
type
Reader = object
data: openArray[char]
current: int

proc initReader(data: openArray[char], offset = 0): Reader =
result = Reader(data: data, current: offset)

let s = "\x01\x00\x00\x00"
doAssert initReader(s).data[0].int == 1

block:
proc foo(x: openArray[char]) =
discard x
Expand Down
Loading