diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 287f81b76d..74cca6d0c5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -150,9 +150,12 @@ proc discardCheck(c: PContext, result: PNode) = while n.kind in skipForDiscardable: n = n.lastSon var s = "expression '" & $n & "' is of type '" & 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: s.add "; for a function call use ()" - localError(n.info, s) + localError(n.info, s) proc semIf(c: PContext, n: PNode): PNode = result = n diff --git a/tests/discard/tneedsdiscard.nim b/tests/discard/tneedsdiscard.nim index 509e8233b3..8d59e7fec0 100644 --- a/tests/discard/tneedsdiscard.nim +++ b/tests/discard/tneedsdiscard.nim @@ -1,6 +1,6 @@ discard """ 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 =