From 08c02f0236eec5957d54cc7f263461e06cb09a2a Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 20 Sep 2022 20:50:48 +0800 Subject: [PATCH] =?UTF-8?q?report=20expression=20has=20no=20type=20other?= =?UTF-8?q?=20than=20has=20to=20be=20used=20(or=20discarded=E2=80=A6=20(#2?= =?UTF-8?q?0392)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit report expression has no type other than has to be used (or discarded) when typ is tyNone in discardCheck --- compiler/semstmts.nim | 3 +++ tests/errmsgs/t8064.nim | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 tests/errmsgs/t8064.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 64d56f81291e8..1e8930fc9b899 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -139,6 +139,9 @@ proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) = var n = newNodeI(nkDiscardStmt, result.info, 1) n[0] = result elif result.typ.kind != tyError and c.config.cmd != cmdInteractive: + if result.typ.kind == tyNone: + localError(c.config, result.info, "expression has no type: " & + renderTree(result, {renderNoComments})) var n = result while n.kind in skipForDiscardable: if n.kind == nkTryStmt: n = n[0] diff --git a/tests/errmsgs/t8064.nim b/tests/errmsgs/t8064.nim new file mode 100644 index 0000000000000..10bb862993889 --- /dev/null +++ b/tests/errmsgs/t8064.nim @@ -0,0 +1,6 @@ +discard """ + errormsg: "expression has no type: values" +""" +import tables + +values \ No newline at end of file