From 7f148838a461397f75853945e33eef29583dcc57 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 27 Jun 2018 21:41:40 +0200 Subject: [PATCH] Reject ptr/ref void types (#8127) Do this during the semantic pass to avoid tripping the following passes. Fixes #6454 --- compiler/semtypes.nim | 3 +++ tests/types/t6456.nim | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/types/t6456.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index d1ebb950ca..dfd4247054 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -177,6 +177,9 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = var t = semTypeNode(c, n.lastSon, nil) if t.kind == tyTypeDesc and tfUnresolved notin t.flags: t = t.base + if t.kind == tyVoid: + const kindToStr: array[tyPtr..tyRef, string] = ["ptr", "ref"] + localError(c.config, n.info, "type '$1 void' is not allowed" % kindToStr[kind]) result = newOrPrevType(kind, prev, c) var isNilable = false # check every except the last is an object: diff --git a/tests/types/t6456.nim b/tests/types/t6456.nim new file mode 100644 index 0000000000..2d2aad3701 --- /dev/null +++ b/tests/types/t6456.nim @@ -0,0 +1,7 @@ +discard """ + line: 6 + errormsg: "type \'ptr void\' is not allowed" +""" + +proc foo(x: ptr void) = + discard