diff options
author | Araq <rumpf_a@web.de> | 2018-02-16 19:41:06 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-02-17 00:40:48 +0100 |
commit | 037ce16f44315271ec3da49bc80e117e29403d20 (patch) | |
tree | 2499083db0c9cb4437b39cf618dc3b6def68b15c | |
parent | f3b8d922169bcf99d7430854d53765082f3ad5a8 (diff) | |
download | Nim-037ce16f44315271ec3da49bc80e117e29403d20.tar.gz |
improve the error message for mutability problems
-rw-r--r-- | compiler/semcall.nim | 8 | ||||
-rw-r--r-- | compiler/semexprs.nim | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index c4f13a237..5bdd817d5 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -133,6 +133,11 @@ proc effectProblem(f, a: PType; result: var string) = result.add "\n This expression can have side effects. Annotate the " & "proc with {.noSideEffect.} to get extended error information." +proc renderNotLValue(n: PNode): string = + result = $n + if n.kind in {nkHiddenStdConv, nkHiddenSubConv, nkHiddenCallConv} and n.len == 2: + result = typeToString(n.typ.skipTypes(abstractVar)) & "(" & result & ")" + proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): (TPreferedDesc, string) = var prefer = preferName @@ -184,7 +189,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): candidates.add "\n" elif err.unmatchedVarParam != 0 and err.unmatchedVarParam < n.len: add(candidates, "for a 'var' type a variable needs to be passed, but '" & - renderTree(n[err.unmatchedVarParam]) & "' is immutable\n") + renderNotLValue(n[err.unmatchedVarParam]) & + "' is immutable\n") for diag in err.diagnostics: add(candidates, diag & "\n") diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 7f58e266e..f1d226160 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -474,7 +474,7 @@ proc newHiddenAddrTaken(c: PContext, n: PNode): PNode = result = newNodeIT(nkHiddenAddr, n.info, makeVarType(c, n.typ)) addSon(result, n) if isAssignable(c, n) notin {arLValue, arLocalLValue}: - localError(n.info, errVarForOutParamNeededX, $n) + localError(n.info, errVarForOutParamNeededX, renderNotLValue(n)) proc analyseIfAddressTaken(c: PContext, n: PNode): PNode = result = n |