fixes #19250; fixes #22259; ORC AssertionDefect not containsManagedMemory(n.typ) (#22823)

fixes #19250
fixes #22259

The strings, seqs, refs types all have this flag, why should closures be
treated differently?

follow up https://github.com/nim-lang/Nim/pull/14336

(cherry picked from commit f5d70e7fa7)
This commit is contained in:
ringabout
2023-10-14 03:34:13 +08:00
committed by narimiran
parent a5a6a4d39e
commit 755a15d8d4
2 changed files with 55 additions and 0 deletions

View File

@@ -2145,6 +2145,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = newOrPrevType(tyError, prev, c)
if n.kind == nkIteratorTy and result.kind == tyProc:
result.flags.incl(tfIterator)
if result.callConv == ccClosure and c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}:
result.flags.incl tfHasAsgn
of nkEnumTy: result = semEnum(c, n, prev)
of nkType: result = n.typ
of nkStmtListType: result = semStmtListType(c, n, prev)

View File

@@ -635,3 +635,56 @@ block: # bug #22664
calc2.stack = calc.stack # This nulls out the object in the stack
doAssert $calc.stack == "@[(kind: Number, num: 200.0)]"
doAssert $calc2.stack == "@[(kind: Number, num: 200.0)]"
block: # bug #19250
type
Bar[T] = object
err: proc(): string
Foo[T] = object
run: proc(): Bar[T]
proc bar[T](err: proc(): string): Bar[T] =
assert not err.isNil
Bar[T](err: err)
proc foo(): Foo[char] =
result.run = proc(): Bar[char] =
# works
# result = Bar[char](err: proc(): string = "x")
# not work
result = bar[char](proc(): string = "x")
proc bug[T](fs: Foo[T]): Foo[T] =
result.run = proc(): Bar[T] =
let res = fs.run()
# works
# var errors = @[res.err]
# not work
var errors: seq[proc(): string]
errors.add res.err
return bar[T] do () -> string:
for err in errors:
result.add res.err()
doAssert bug(foo()).run().err() == "x"
block: # bug #22259
type
ProcWrapper = tuple
p: proc() {.closure.}
proc f(wrapper: ProcWrapper) =
let s = @[wrapper.p]
let a = [wrapper.p]
proc main =
# let wrapper: ProcWrapper = ProcWrapper(p: proc {.closure.} = echo 10)
let wrapper: ProcWrapper = (p: proc {.closure.} = echo 10)
f(wrapper)
main()