Skip to content

Commit 834dcab

Browse files
committed
fixes #24760; Noncopyable base type ignored
1 parent 82891e6 commit 834dcab

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

compiler/injectdestructors.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ proc isLastReadImpl(n: PNode; c: var Con; scope: var Scope): bool =
162162
else:
163163
result = false
164164

165-
proc isLastRead(n: PNode; c: var Con; s: var Scope): bool =
165+
template hasDestructorOrAsgn(c: var Con, typ: PType): bool =
166166
# bug #23354; an object type could have a non-trival assignements when it is passed to a sink parameter
167-
if not hasDestructor(c, n.typ) and (n.typ.kind != tyObject or isTrival(getAttachedOp(c.graph, n.typ, attachedAsgn))): return true
167+
hasDestructor(c, typ) or (typ.kind == tyObject and not isTrival(getAttachedOp(c.graph, typ, attachedAsgn)))
168+
169+
proc isLastRead(n: PNode; c: var Con; s: var Scope): bool =
170+
if not hasDestructorOrAsgn(c, n.typ): return true
168171

169172
let m = skipConvDfa(n)
170173
result = (m.kind == nkSym and sfSingleUsedTemp in m.sym.flags) or
@@ -449,7 +452,7 @@ proc passCopyToSink(n: PNode; c: var Con; s: var Scope): PNode =
449452
result = newNodeIT(nkStmtListExpr, n.info, n.typ)
450453
let nTyp = n.typ.skipTypes(tyUserTypeClasses)
451454
let tmp = c.getTemp(s, nTyp, n.info)
452-
if hasDestructor(c, nTyp):
455+
if hasDestructorOrAsgn(c, nTyp):
453456
let typ = nTyp.skipTypes({tyGenericInst, tyAlias, tySink})
454457
let op = getAttachedOp(c.graph, typ, attachedDup)
455458
if op != nil and tfHasOwned notin typ.flags:

tests/arc/t24760.nim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
discard """
2+
matrix: "--mm:refc; --mm:orc"
3+
errormsg: "=dup' is not available for type <B>, which is inferred from unavailable '=copy'; requires a copy because it's not the last read of 'b'; another read is done here: t24760.nim(19, 8); routine: g"
4+
"""
5+
6+
type
7+
A {.inheritable.} = object
8+
B = object of A
9+
10+
proc `=copy`(a: var A, x: A) {.error.}
11+
#proc `=copy`(a: var B, x: B) {.error.}
12+
13+
proc ffff(v: sink B) =
14+
echo v
15+
16+
proc g() =
17+
var b: B
18+
ffff(b)
19+
ffff(b)
20+
g()

0 commit comments

Comments
 (0)