* fix #16722

* fix spacing

* spacing
This commit is contained in:
cooldome 2021-01-15 18:16:24 +00:00 • committed by GitHub
commit fc9cf2088d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 4 deletions

View file

@ -1330,7 +1330,7 @@ proc genHook(m: BModule; t: PType; info: TLineInfo; op: TTypeAttachedOp): Rope =
proc genTypeInfoV2Impl(m: BModule, t, origType: PType, name: Rope; info: TLineInfo) = proc genTypeInfoV2Impl(m: BModule, t, origType: PType, name: Rope; info: TLineInfo) =
var typeName: Rope var typeName: Rope
if t.kind == tyObject: if t.kind in {tyObject, tyDistinct}:
if incompleteType(t): if incompleteType(t):
localError(m.config, info, "request for RTTI generation for incomplete object: " & localError(m.config, info, "request for RTTI generation for incomplete object: " &
typeToString(t)) typeToString(t))
@ -1353,7 +1353,8 @@ proc genTypeInfoV2Impl(m: BModule, t, origType: PType, name: Rope; info: TLineIn
proc genTypeInfoV2(m: BModule, t: PType; info: TLineInfo): Rope = proc genTypeInfoV2(m: BModule, t: PType; info: TLineInfo): Rope =
let origType = t let origType = t
var t = skipTypes(origType, irrelevantForBackend + tyUserTypeClasses) # distinct types can have their own destructors
var t = skipTypes(origType, irrelevantForBackend + tyUserTypeClasses - {tyDistinct})
let prefixTI = if m.hcrOn: "(" else: "(&" let prefixTI = if m.hcrOn: "(" else: "(&"

View file

@ -361,7 +361,7 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
result = true result = true
proc addDestructorCall(c: var TLiftCtx; orig: PType; body, x: PNode) = proc addDestructorCall(c: var TLiftCtx; orig: PType; body, x: PNode) =
let t = orig.skipTypes(abstractInst) let t = orig.skipTypes(abstractInst - {tyDistinct})
var op = t.destructor var op = t.destructor
if op != nil and sfOverriden in op.flags: if op != nil and sfOverriden in op.flags:

View file

@ -524,6 +524,7 @@ proc transformConv(c: PTransf, n: PNode): PNode =
result[0] = transform(c, n[1]) result[0] = transform(c, n[1])
else: else:
result = transform(c, n[1]) result = transform(c, n[1])
result.typ = n.typ
else: else:
result = transformSons(c, n) result = transformSons(c, n)
of tyObject: of tyObject:
@ -536,6 +537,7 @@ proc transformConv(c: PTransf, n: PNode): PNode =
result[0] = transform(c, n[1]) result[0] = transform(c, n[1])
else: else:
result = transform(c, n[1]) result = transform(c, n[1])
result.typ = n.typ
of tyGenericParam, tyOrdinal: of tyGenericParam, tyOrdinal:
result = transform(c, n[1]) result = transform(c, n[1])
# happens sometimes for generated assignments, etc. # happens sometimes for generated assignments, etc.

View file

@ -126,3 +126,45 @@ proc main =
echo avals.len, " ", rankdef.len echo avals.len, " ", rankdef.len
main() main()
#------------------------------------------------------------------------------
# Issue #16722, ref on distinct type, wrong destructors called
#------------------------------------------------------------------------------
type
Obj = object of RootObj
ObjFinal = object
ObjRef = ref Obj
ObjFinalRef = ref ObjFinal
D = distinct Obj
DFinal = distinct ObjFinal
DRef = ref D
DFinalRef = ref DFinal
proc `=destroy`(o: var Obj) =
doAssert false, "no Obj is constructed in this sample"
proc `=destroy`(o: var ObjFinal) =
doAssert false, "no ObjFinal is constructed in this sample"
var dDestroyed: int
proc `=destroy`(d: var D) =
dDestroyed.inc
proc `=destroy`(d: var DFinal) =
dDestroyed.inc
func newD(): DRef =
DRef ObjRef()
func newDFinal(): DFinalRef =
DFinalRef ObjFinalRef()
proc testRefs() =
discard newD()
discard newDFinal()
testRefs()
doAssert(dDestroyed == 2)