* fixes #13583; enfore void for nkWhileStmt * one more case
This commit is contained in:
parent
b5a008bac8
commit
d4afa53fd5
2 changed files with 39 additions and 0 deletions
|
|
@ -38,6 +38,8 @@ const
|
||||||
errPragmaOnlyInHeaderOfProcX = "pragmas are only allowed in the header of a proc; redefinition of $1"
|
errPragmaOnlyInHeaderOfProcX = "pragmas are only allowed in the header of a proc; redefinition of $1"
|
||||||
errCannotAssignToGlobal = "cannot assign local to global variable"
|
errCannotAssignToGlobal = "cannot assign local to global variable"
|
||||||
|
|
||||||
|
proc implicitlyDiscardable(n: PNode): bool
|
||||||
|
|
||||||
proc semDiscard(c: PContext, n: PNode): PNode =
|
proc semDiscard(c: PContext, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
checkSonsLen(n, 1, c.config)
|
checkSonsLen(n, 1, c.config)
|
||||||
|
|
@ -101,6 +103,9 @@ proc semWhile(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||||
result.typ = c.enforceVoidContext
|
result.typ = c.enforceVoidContext
|
||||||
elif efInTypeof in flags:
|
elif efInTypeof in flags:
|
||||||
result.typ = n[1].typ
|
result.typ = n[1].typ
|
||||||
|
elif implicitlyDiscardable(n[1]):
|
||||||
|
result[1].typ = c.enforceVoidContext
|
||||||
|
result.typ = c.enforceVoidContext
|
||||||
|
|
||||||
proc semProc(c: PContext, n: PNode): PNode
|
proc semProc(c: PContext, n: PNode): PNode
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,3 +65,37 @@ proc main2() =
|
||||||
|
|
||||||
main1()
|
main1()
|
||||||
main2()
|
main2()
|
||||||
|
|
||||||
|
block: # bug #13583
|
||||||
|
block:
|
||||||
|
proc hello(): int {.discardable.} = 12
|
||||||
|
|
||||||
|
iterator test(): int {.closure.} =
|
||||||
|
while true:
|
||||||
|
hello()
|
||||||
|
|
||||||
|
let t = test
|
||||||
|
|
||||||
|
block:
|
||||||
|
proc hello(): int {.discardable.} = 12
|
||||||
|
|
||||||
|
iterator test(): int {.closure.} =
|
||||||
|
while true:
|
||||||
|
block:
|
||||||
|
yield 12
|
||||||
|
hello()
|
||||||
|
|
||||||
|
let t = test
|
||||||
|
doAssert t() == 12
|
||||||
|
|
||||||
|
block:
|
||||||
|
proc hello(): int {.discardable.} = 12
|
||||||
|
|
||||||
|
iterator test(): int {.closure.} =
|
||||||
|
while true:
|
||||||
|
yield 12
|
||||||
|
hello()
|
||||||
|
|
||||||
|
let t = test
|
||||||
|
doAssert t() == 12
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue