From ce148e71ef49dab3d8e61499bce40fd5718ecff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Tue, 6 Aug 2019 01:26:53 +0200 Subject: [PATCH] disallow static in return type (#9686) [nobackport] --- compiler/semtypes.nim | 3 +++ compiler/types.nim | 4 +++- tests/errmsgs/tstaticresult.nim | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/tstaticresult.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 3bc2f4ede7..a2425e9fa1 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1230,6 +1230,9 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, # 'p(): auto' and 'p(): expr' are equivalent, but the rest of the # compiler is hardly aware of 'auto': r = newTypeS(tyUntyped, c) + elif r.kind == tyStatic: + # type allowed should forbid this type + discard else: if r.sym == nil or sfAnon notin r.sym.flags: let lifted = liftParamType(c, kind, genericParams, r, "result", diff --git a/compiler/types.nim b/compiler/types.nim index e41f457800..20f0d516eb 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1238,7 +1238,9 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, of tyTypeDesc: # XXX: This is still a horrible idea... result = nil - of tyUntyped, tyTyped, tyStatic: + of tyStatic: + if kind notin {skParam}: result = t + of tyUntyped, tyTyped: if kind notin {skParam, skResult}: result = t of tyVoid: if taField notin flags: result = t diff --git a/tests/errmsgs/tstaticresult.nim b/tests/errmsgs/tstaticresult.nim new file mode 100644 index 0000000000..bc534c7a81 --- /dev/null +++ b/tests/errmsgs/tstaticresult.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: ''' +invalid type: 'static[int]' in this context: 'proc (x: int): static[int]' for proc +''' +""" + +proc foo(x: int): static int = + x + 123 + +echo foo(123)