From 730b1b2b878f18a3bee71dc1dcd463891213cd83 Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Wed, 19 Dec 2018 20:48:57 +0530 Subject: [PATCH] proc does not take untyped/typed as argument (#9981) * proc does not take untyped/typed as argument * Add TODO --- compiler/semtypes.nim | 5 +++++ tests/proc/typed.nim | 7 +++++++ tests/proc/untyped.nim | 7 +++++++ 3 files changed, 19 insertions(+) create mode 100644 tests/proc/typed.nim create mode 100644 tests/proc/untyped.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index dc27e5823b..e0f04c22fa 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1064,6 +1064,11 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, if hasType: typ = semParamType(c, a.sons[length-2], constraint) + var owner = getCurrOwner(c).owner + # TODO: Disallow typed/untyped in procs in the compiler/stdlib + if (owner.kind != skModule or owner.owner.name.s != "stdlib") and + kind == skProc and (typ.kind == tyStmt or typ.kind == tyExpr): + localError(c.config, a.sons[length-2].info, "'" & typ.sym.name.s & "' is only allowed in templates and macros") if hasDefault: def = a[^1] diff --git a/tests/proc/typed.nim b/tests/proc/typed.nim new file mode 100644 index 0000000000..2e81176347 --- /dev/null +++ b/tests/proc/typed.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "'typed' is only allowed in templates and macros" + line: 6 +""" + +proc fun(x:typed)=discard +fun(10) diff --git a/tests/proc/untyped.nim b/tests/proc/untyped.nim new file mode 100644 index 0000000000..f8b3ead7bf --- /dev/null +++ b/tests/proc/untyped.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "'untyped' is only allowed in templates and macros" + line: 6 +""" + +proc fun(x:untyped)=discard +fun(10)