From f7cb0322c2d7939398a064d2f31b63ed8902b1c6 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 3 Oct 2024 00:25:59 +0800 Subject: [PATCH] improve error messages for illegalCapture (#24214) ref https://forum.nim-lang.org/t/12536 Use a general recommendation to avoid some weird error messages like `` etc. --- compiler/lambdalifting.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 2d38d9a69b..54cdfc5bc0 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -300,8 +300,8 @@ proc markAsClosure(g: ModuleGraph; owner: PSym; n: PNode) = 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." & - " Consider using a which can be captured.") % - [s.name.s, typeToString(s.typ), g.config$s.info]) + " Consider using a which can be captured.") % + [s.name.s, typeToString(s.typ.skipTypes({tyVar})), g.config$s.info]) elif not (owner.typ.isClosure or owner.isNimcall and not owner.isExplicitCallConv or isEnv): localError(g.config, n.info, "illegal capture '$1' because '$2' has the calling convention: <$3>" % [s.name.s, owner.name.s, $owner.typ.callConv])