fixes #9940; genericAssign does not take care of the importC variables in refc [backport] (#23761)

fixes #9940

(cherry picked from commit 828cd58d8a)
This commit is contained in:
ringabout
2024-06-27 00:24:51 +08:00
committed by narimiran
parent 6789859503
commit fda43d1f0a
2 changed files with 29 additions and 1 deletions

View File

@@ -1246,7 +1246,7 @@ proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo
else:
genTypeInfoAuxBase(m, typ, origType, name, rope("0"), info)
var tmp = getNimNode(m)
if not isImportedType(typ):
if (not isImportedType(typ)) or tfCompleteStruct in typ.flags:
genObjectFields(m, typ, origType, typ.n, tmp, info)
m.s[cfsTypeInit3].addf("$1.node = &$2;$n", [tiNameForHcr(m, name), tmp])
var t = typ[0]

View File

@@ -4,6 +4,7 @@ success
M1 M2
ok
'''
matrix: "--mm:refc;--mm:orc"
"""
type
@@ -132,3 +133,30 @@ proc foo = # bug #23280
doAssert L mod 6 == 0
foo()
block: # bug #9940
{.emit:"""/*TYPESECTION*/
typedef struct { int base; } S;
""".}
type S {.importc: "S", completeStruct.} = object
base: cint
proc init(x:ptr S) =
x.base = 1
type
Foo = object
a: seq[float]
b: seq[float]
c: seq[float]
d: seq[float]
s: S
proc newT(): Foo =
var t: Foo
t.s.addr.init
doAssert t.s.base == 1
t
var t = newT()
doAssert t.s.base == 1