summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCarlo Capocasa <carlo@capocasa.net>2022-06-11 18:23:31 +0200
committerGitHub <noreply@github.com>2022-06-11 18:23:31 +0200
commite2e663a14389500b07e2f6fcd5c231536bdf76a0 (patch)
treed4664542ea9e506a65eeb67511ca8aa097c1dc4d
parentac89eead8a40a1a8ee170a4650a1d47e203da14c (diff)
downloadNim-e2e663a14389500b07e2f6fcd5c231536bdf76a0.tar.gz
Friendlier error message with solution (#19880)
* Add helpful suggestion, should always apply

* mention var param limitation in async docs

* Update compiler/lambdalifting.nim

whoops thanks

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
-rw-r--r--compiler/lambdalifting.nim3
-rw-r--r--lib/pure/asyncdispatch.nim5
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim
index 4b7ca89cd..96edba8c8 100644
--- a/compiler/lambdalifting.nim
+++ b/compiler/lambdalifting.nim
@@ -288,7 +288,8 @@ proc markAsClosure(g: ModuleGraph; owner: PSym; n: PNode) =
   if illegalCapture(s):
     localError(g.config, n.info,
       ("'$1' is of type <$2> which cannot be captured as it would violate memory" &
-       " safety, declared here: $3; using '-d:nimNoLentIterators' helps in some cases") %
+       " safety, declared here: $3; using '-d:nimNoLentIterators' helps in some cases." &
+       " Consider using a <ref $2> which can be captured.") %
       [s.name.s, typeToString(s.typ), g.config$s.info])
   elif not (owner.typ.callConv == ccClosure or owner.typ.callConv == ccNimCall and tfExplicitCallConv notin owner.typ.flags):
     localError(g.config, n.info, "illegal capture '$1' because '$2' has the calling convention: <$3>" %
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index 755f59ff7..0d406b271 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -98,6 +98,10 @@
 ## `await`. The following section shows different ways that you can handle
 ## exceptions in async procs.
 ##
+## .. caution::
+##     Procedures marked {.async.} do not support mutable parameters such
+##     as `var int`. References such as `ref int` should be used instead.
+##
 ## Handling Exceptions
 ## -------------------
 ##
@@ -192,6 +196,7 @@
 ## ================
 ##
 ## * The effect system (`raises: []`) does not work with async procedures.
+## * Mutable parameters are not supported by async procedures.
 ##
 ##
 ## Multiple async backend support