summary refs log tree commit diff stats
path: root/tests/objects/tobjconstr.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/objects/tobjconstr.nim')
-rw-r--r--tests/objects/tobjconstr.nim43
1 files changed, 23 insertions, 20 deletions
diff --git a/tests/objects/tobjconstr.nim b/tests/objects/tobjconstr.nim
index 1e4d89d68..ee5a5b221 100644
--- a/tests/objects/tobjconstr.nim
+++ b/tests/objects/tobjconstr.nim
@@ -50,27 +50,30 @@ type
   BS = object of B
   C = object of BS
     z*: int
-# inherited fields are ignored, so no fields are set
-when true:
-  var
-    o: B
-  o = B(x: 123)
-  echo o
-  o = B(y: 678, x: 123)
-  echo o
 
-# inherited fields are ignored
-echo C(x: 128, z: 89)          # (y: 0, x: 0)
-echo B(y: 678, x: 123)  # (y: 678, x: 0)
-echo B(x: 123, y: 678)  # (y: 678, x: 0)
+proc main2 =
+  # inherited fields are ignored, so no fields are set
+  when true:
+    var
+      o: B
+    o = B(x: 123)
+    echo o
+    o = B(y: 678, x: 123)
+    echo o
 
-when true:
-  # correct, both with `var` and `let`;
-  var b=B(x: 123)
-  echo b                  # (y: 0, x: 123)
-  b=B(y: 678, x: 123)
-  echo b                  # (y: 678, x: 123)
-  b=B(y: b.x, x: b.y)
-  echo b                  # (y: 123, x: 678)
+  # inherited fields are ignored
+  echo C(x: 128, z: 89)          # (y: 0, x: 0)
+  echo B(y: 678, x: 123)  # (y: 678, x: 0)
+  echo B(x: 123, y: 678)  # (y: 678, x: 0)
 
+  when true:
+    # correct, both with `var` and `let`;
+    var b=B(x: 123)
+    echo b                  # (y: 0, x: 123)
+    b=B(y: 678, x: 123)
+    echo b                  # (y: 678, x: 123)
+    b=B(y: b.x, x: b.y)
+    echo b                  # (y: 123, x: 678)
+
+main2()
 GC_fullCollect()