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>
This commit is contained in:
Juan M Gómez
2023-09-08 09:46:40 +01:00
committed by GitHub
parent 2a8c759df0
commit d45270bdf7
2 changed files with 30 additions and 2 deletions

View File

@@ -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
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()