summary refs log tree commit diff stats
path: root/tests/vm/tcopy_global_var.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm/tcopy_global_var.nim')
-rw-r--r--tests/vm/tcopy_global_var.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/vm/tcopy_global_var.nim b/tests/vm/tcopy_global_var.nim
new file mode 100644
index 000000000..eadd27b9a
--- /dev/null
+++ b/tests/vm/tcopy_global_var.nim
@@ -0,0 +1,30 @@
+discard """
+  nimout: "static done"
+"""
+
+# bug #5269
+
+proc assertEq[T](arg0, arg1: T): void =
+  assert arg0 == arg1, $arg0 & " == " & $arg1
+
+type
+  MyType = object
+    str: string
+    a: int
+
+block:
+  var localValue = MyType(str: "Original strning, (OK)", a: 0)
+  var valueCopy = localValue
+  valueCopy.a = 123
+  valueCopy.str = "Modified strning, (not OK when in localValue)"
+  assertEq(localValue.str, "Original strning, (OK)")
+  assertEq(localValue.a,   0)
+
+static:
+  var localValue = MyType(str: "Original strning, (OK)", a: 0)
+  var valueCopy = localValue
+  valueCopy.a = 123
+  valueCopy.str = "Modified strning, (not OK when in localValue)"
+  assertEq(localValue.str, "Original strning, (OK)")
+  assertEq(localValue.a,   0)
+  echo "static done"