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 #24369 #24370

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
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 lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2969,5 +2969,4 @@ proc arrayWith*[T](y: T, size: static int): array[size, T] {.raises: [].} =
when nimvm:
result[i] = y
else:
# TODO: fixme it should be `=dup`
result[i] = y
result[i] = `=dup`(y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is that the comment is wrong and the explicit =dup should not be necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understand correctly, the current implementation of arrayWith is correct as it has been so far (as we actually will copy y, but in the example type we forbid copying values, so semantics seem correct to me). But maybe there would need to be an alternative implementation of this function to implement array initialization using the default proc to generate the default value instead of passing in a default value?

If my assumptions are correct, I guess I would need to make changes in the defaultNodeField proc. Somewhere around here:

result = semExpr(c, newTree(nkCall, newSymNode(getSysSym(c.graph, a.info, "arrayWith"), a.info),
correct?

10 changes: 10 additions & 0 deletions tests/system/tcopyprotected_arrayinit.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type
Bar = object
b: int = 1

Foo = object
f: array[1, Bar]

proc `=copy`(dest: var Bar, source: Bar) {.error.}

discard Foo()
Loading