mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 00:35:26 +00:00
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:
@@ -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()
|
||||
Reference in New Issue
Block a user