summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/sugar.nim2
-rw-r--r--tests/closure/t15594.nim10
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim
index 92e9f662a..dd44c731d 100644
--- a/lib/pure/sugar.nim
+++ b/lib/pure/sugar.nim
@@ -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]
                else: 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))
   result = newNimNode(nnkCall)
   result.add(newProc(newEmptyNode(), params, body, nnkProcDef))
diff --git a/tests/closure/t15594.nim b/tests/closure/t15594.nim
new file mode 100644
index 000000000..aacd9ed84
--- /dev/null
+++ b/tests/closure/t15594.nim
@@ -0,0 +1,10 @@
+discard """
+  errormsg: "The variable name cannot be `result`!"
+"""
+
+import sugar
+
+proc begin(): int =
+  capture result:
+    echo 1+1
+  result