mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
disallow static in return type (#9686) [nobackport]
This commit is contained in:
committed by
Andreas Rumpf
parent
42e83ac24c
commit
ce148e71ef
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
10
tests/errmsgs/tstaticresult.nim
Normal file
10
tests/errmsgs/tstaticresult.nim
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user