mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user