summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJuan M Gómez <info@jmgomez.me>2023-09-08 09:46:40 +0100
committerGitHub <noreply@github.com>2023-09-08 10:46:40 +0200
commitd45270bdf721e195a9dae344f9a3285d066c3932 (patch)
tree4bfe25db33eea5555ad37378fb67cbb7a255be90 /tests
parent2a8c759df0e8a952f7cbea8539e3fb7aa234795a (diff)
downloadNim-d45270bdf721e195a9dae344f9a3285d066c3932.tar.gz
fixes #22662 Procs with constructor pragma doesn't initialize object's fields (#22665)
fixes #22662 Procs with constructor pragma doesn't initialize object's
fields

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/cpp/tconstructor.nim23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/cpp/tconstructor.nim b/tests/cpp/tconstructor.nim
index d4d6a7ccf..b69162661 100644
--- a/tests/cpp/tconstructor.nim
+++ b/tests/cpp/tconstructor.nim
@@ -3,6 +3,10 @@ discard """
   cmd: "nim cpp $file"
   output: '''
 1
+0
+123
+0
+123
 '''
 """
 
@@ -52,4 +56,21 @@ proc makeCppClass(): NimClass {. constructor: "NimClass() : CppClass(0, 0) ".} =
   this.x = 1
 
 let nimClass = makeNimClass(1)
-var nimClassDef {.used.}: NimClass  #since we explictly defined the default constructor we can declare the obj
\ No newline at end of file
+var nimClassDef {.used.}: NimClass  #since we explictly defined the default constructor we can declare the obj
+
+#bug: 22662
+type
+  BugClass* = object
+    x: int          # Not initialized
+
+proc makeBugClass(): BugClass {.constructor.} =
+  discard
+
+proc main =
+  for i in 0 .. 1:
+    var n = makeBugClass()
+    echo n.x
+    n.x = 123
+    echo n.x
+
+main()
\ No newline at end of file