more chatty error message for the 'discard' checking

This commit is contained in:
Andreas Rumpf 2018-02-05 16:49:06 +01:00
commit d72578b3dd
2 changed files with 5 additions and 2 deletions

View file

@ -150,6 +150,9 @@ proc discardCheck(c: PContext, result: PNode) =
while n.kind in skipForDiscardable: n = n.lastSon while n.kind in skipForDiscardable: n = n.lastSon
var s = "expression '" & $n & "' is of type '" & var s = "expression '" & $n & "' is of type '" &
result.typ.typeToString & "' and has to be discarded" result.typ.typeToString & "' and has to be discarded"
if result.info.line != n.info.line or
result.info.fileIndex != n.info.fileIndex:
s.add "; start of expression here: " & $result.info
if result.typ.kind == tyProc: if result.typ.kind == tyProc:
s.add "; for a function call use ()" s.add "; for a function call use ()"
localError(n.info, s) localError(n.info, s)

View file

@ -1,6 +1,6 @@
discard """ discard """
line: 10 line: 10
errormsg: '''expression 'open(f, "arg.txt", fmRead, -1)' is of type 'bool' and has to be discarded''' errormsg: '''expression 'open(f, "arg.txt", fmRead, -1)' is of type 'bool' and has to be discarded; start of expression here: tneedsdiscard.nim(7, 2)'''
""" """
proc p = proc p =