From d738ed9c927a881e6ffc7d21c4a87197f6689283 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 19 Mar 2018 19:39:44 +0100 Subject: [PATCH] better error messages for illegal captures --- compiler/lambdalifting.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index fca5ef52eb..bc05ec80c7 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -275,8 +275,12 @@ proc freshVarForClosureIter*(s, owner: PSym): PNode = proc markAsClosure(owner: PSym; n: PNode) = let s = n.sym - if illegalCapture(s) or owner.typ.callConv notin {ccClosure, ccDefault}: - localError(n.info, errIllegalCaptureX, s.name.s) + if illegalCapture(s): + localError(n.info, "illegal capture '$1' of type <$2> which is declared here: $3" % + [s.name.s, typeToString(s.typ), $s.info]) + elif owner.typ.callConv notin {ccClosure, ccDefault}: + localError(n.info, "illegal capture '$1' because '$2' has the calling convention: <$3>" % + [s.name.s, owner.name.s, CallingConvToStr[owner.typ.callConv]]) incl(owner.typ.flags, tfCapturesEnv) owner.typ.callConv = ccClosure