From 3cbb8e81b53887c1a8fcd7464f2e3252e9f8c4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Thu, 8 Nov 2018 17:07:02 +0100 Subject: [PATCH] fix #8011 --- compiler/ccgtypes.nim | 2 ++ compiler/semstmts.nim | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 386d7f60cec2..decf5688aee4 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -146,6 +146,8 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind = return mapType(conf, typ.lastSon) of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias, tySink, tyInferred: + if typ.sons.len == 0: + internalError(conf, "typ has no last son") result = mapType(conf, lastSon(typ)) of tyEnum: if firstOrd(conf, typ) < 0: diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5c7f866ce96f..a2ca50fdad30 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -41,8 +41,12 @@ proc semDiscard(c: PContext, n: PNode): PNode = checkSonsLen(n, 1, c.config) if n.sons[0].kind != nkEmpty: n.sons[0] = semExprWithType(c, n.sons[0]) - if isEmptyType(n.sons[0].typ) or n.sons[0].typ.kind == tyNone or n.sons[0].kind == nkTypeOfExpr: + let sonType = n.sons[0].typ + if isEmptyType(sonType) or sonType.kind == tyNone or n.sons[0].kind == nkTypeOfExpr: localError(c.config, n.info, errInvalidDiscard) + if sonType.kind == tyProc: + # tyProc is disallowed to prevent ``discard foo`` to pass, when ``discard foo()`` is meant. + localError(c.config, n.info, "illegal discard proc, did you mean: " & $n[0] & "()") proc semBreakOrContinue(c: PContext, n: PNode): PNode = result = n