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

Top level variables are moved sometimes #23524

Closed
beef331 opened this issue Apr 21, 2024 · 0 comments · Fixed by #23529
Closed

Top level variables are moved sometimes #23524

beef331 opened this issue Apr 21, 2024 · 0 comments · Fixed by #23529

Comments

@beef331
Copy link
Collaborator

beef331 commented Apr 21, 2024

Description

Depending on what hooks exist for a type top level variables might be moved instead of copied:

type MyType = object
  a: int

proc `=destroy`(typ: MyType) = echo "Destroyed: ", typ.a

var t1 = MyType(a: 100)
var t2 = t1 # Should be a copy?

proc main() =
  t2 = t1
  echo t1
  echo t2

main()

Nim Version

2.0.4 and devel

Current Output

(a: 0)
(a: 0)
Destroyed: 0
Destroyed: 0

Expected Output

(a: 100)
(a: 100)
Destroyed: 100
Destroyed: 100

Possible Solution

No response

Additional Information

No response

@ringabout ringabout self-assigned this Apr 22, 2024
Araq pushed a commit that referenced this issue Apr 24, 2024
…e` (#23529)

fixes #23524

```nim
proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool =
  ...
  result = n.kind == nkSym and n.sym.owner == owner and
    {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and
    (n.sym.kind != skParam or isSinkParam(n.sym))
```
In `isAnalysableFieldAccess`, globals, cursors are already rejected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants