nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).

Home Page:https://nim-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top level variables are moved sometimes

beef331 opened this issue · comments

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