summary refs log tree commit diff stats
path: root/tests/objects
diff options
context:
space:
mode:
Diffstat (limited to 'tests/objects')
-rw-r--r--tests/objects/tobjconstr.nim38
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/objects/tobjconstr.nim b/tests/objects/tobjconstr.nim
index 226fe98f7..12478f621 100644
--- a/tests/objects/tobjconstr.nim
+++ b/tests/objects/tobjconstr.nim
@@ -8,7 +8,14 @@ discard """
 (k: kindA, a: (x: abc, z: [1, 7, 3]), method: ())
 (k: kindA, a: (x: abc, z: [1, 8, 3]), method: ())
 (k: kindA, a: (x: abc, z: [1, 9, 3]), method: ())
-(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ())'''
+(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ())
+(x: 123)
+(x: 123)
+(z: 89, y: 0, x: 128)
+(y: 678, x: 123)
+(y: 678, x: 123)
+(y: 0, x: 123)
+(y: 678, x: 123)'''
 """
 
 type
@@ -39,3 +46,32 @@ proc main() =
 
 main()
 
+# bug #6294
+type
+  A = object of RootObj
+    x*: int
+  B = object of A
+    y*: int
+  BS = object of B
+  C = object of BS
+    z*: int
+# inherited fields are ignored, so no fields are set
+when true:
+  var
+    o: A
+  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)
+
+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)