parent
6fa82a5b3a
commit
eb429988cd
2 changed files with 12 additions and 0 deletions
|
|
@ -207,6 +207,8 @@ macro capture*(locals: varargs[typed], body: untyped): untyped {.since: (1, 1).}
|
||||||
let locals = if locals.len == 1 and locals[0].kind == nnkBracket: locals[0]
|
let locals = if locals.len == 1 and locals[0].kind == nnkBracket: locals[0]
|
||||||
else: locals
|
else: locals
|
||||||
for arg in locals:
|
for arg in locals:
|
||||||
|
if arg.strVal == "result":
|
||||||
|
error("The variable name cannot be `result`!", arg)
|
||||||
params.add(newIdentDefs(ident(arg.strVal), freshIdentNodes getTypeInst arg))
|
params.add(newIdentDefs(ident(arg.strVal), freshIdentNodes getTypeInst arg))
|
||||||
result = newNimNode(nnkCall)
|
result = newNimNode(nnkCall)
|
||||||
result.add(newProc(newEmptyNode(), params, body, nnkProcDef))
|
result.add(newProc(newEmptyNode(), params, body, nnkProcDef))
|
||||||
|
|
|
||||||
10
tests/closure/t15594.nim
Normal file
10
tests/closure/t15594.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "The variable name cannot be `result`!"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sugar
|
||||||
|
|
||||||
|
proc begin(): int =
|
||||||
|
capture result:
|
||||||
|
echo 1+1
|
||||||
|
result
|
||||||
Loading…
Add table
Add a link
Reference in a new issue