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

Array field that has array-element type with copy-protector and default value set on a field will yield error #24369

Open
saemideluxe opened this issue Oct 27, 2024 · 0 comments · May be fixed by #24370

Comments

@saemideluxe
Copy link

Description

Sorry for the bad title, I am not sure how describe this better. However, I have a rather short piece of code that reproduces the code.

The following code will give a compiler error.

type
  Bar = object
    b: int = 1

  Foo = object
    f*: array[1, Bar]

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

discard Foo()

Nim Version

Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1
active boot switches: -d:release

Current Output

....../nim-2.2.0/lib/system.nim(2955, 19) Error: '=copy' is not available for type <Bar>; requires a copy because it's not the last read of 'y'; try to make y a 'sink' parameter; routine: arrayWith

Expected Output

<no compilation error>

Known Workarounds

  • Removing the default value for Bar.b will get rid of the error.
  • Removing the copy-prevention will get rid of the error.
  • Using =dup will get rid of the error (see comment below)
  • Not using the object-initialiser will get rid of the error (i.g. not using Foo() and setting fields manually).

Additional Information

I noticed that there is a comment # TODO: fixme it should be `=dup` just at the line where the error is reported. When changing that according line to result[i] = `=dup`(y) the compiler error is gone. Not sure if that has any further impact in other places though...

saemideluxe added a commit to saemideluxe/Nim that referenced this issue Oct 27, 2024
@saemideluxe saemideluxe linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant