tcopy_global_var.nim 751 B

12345678910111213141516171819202122232425262728293031
  1. discard """
  2. nimout: "static done"
  3. """
  4. # bug #5269
  5. proc assertEq[T](arg0, arg1: T): void =
  6. assert arg0 == arg1, $arg0 & " == " & $arg1
  7. type
  8. MyType = object
  9. str: string
  10. a: int
  11. block:
  12. var localValue = MyType(str: "Original strning, (OK)", a: 0)
  13. var valueCopy = localValue
  14. valueCopy.a = 123
  15. valueCopy.str = "Modified strning, (not OK when in localValue)"
  16. assertEq(localValue.str, "Original strning, (OK)")
  17. assertEq(localValue.a, 0)
  18. static:
  19. var localValue = MyType(str: "Original strning, (OK)", a: 0)
  20. var valueCopy = localValue
  21. valueCopy.a = 123
  22. valueCopy.str = "Modified strning, (not OK when in localValue)"
  23. assertEq(localValue.str, "Original strning, (OK)")
  24. assertEq(localValue.a, 0)
  25. echo "static done"