diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-08-26 20:14:21 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-08-26 20:14:21 +0200 |
commit | ae9bb4474bdfb6740cbf50875febdf9689718601 (patch) | |
tree | 2e413afe46f8b888cdc640e534aa5e5b2367a33f | |
parent | 88814bbe98fe43ca4f3c168b7d77ebb820838e7a (diff) | |
download | Nim-ae9bb4474bdfb6740cbf50875febdf9689718601.tar.gz |
fixes #12033 (#12039)
-rw-r--r-- | compiler/semstmts.nim | 4 | ||||
-rw-r--r-- | tests/proc/tillegalreturntype.nim | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 07aaf0eca..0d9d1af39 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1904,6 +1904,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, discard popProcCon(c) else: + if s.kind in {skProc, skFunc} and s.typ[0] != nil and s.typ[0].kind == tyUntyped: + # `auto` is represented as `tyUntyped` at this point in compilation. + localError(c.config, n[paramsPos][0].info, "return type 'auto' cannot be used in forward declarations") + if s.kind == skMethod: semMethodPrototype(c, s, n) if proto != nil: localError(c.config, n.info, errImplOfXexpected % proto.name.s) if {sfImportc, sfBorrow, sfError} * s.flags == {} and s.magic == mNone: diff --git a/tests/proc/tillegalreturntype.nim b/tests/proc/tillegalreturntype.nim index be9e2147e..e26c44bea 100644 --- a/tests/proc/tillegalreturntype.nim +++ b/tests/proc/tillegalreturntype.nim @@ -1,8 +1,11 @@ discard """ cmd: "nim check $file" errmsg: "" - nimout: '''tillegalreturntype.nim(8, 11) Error: return type 'typed' is only valid for macros and templates -tillegalreturntype.nim(11, 11) Error: return type 'untyped' is only valid for macros and templates''' + nimout: ''' +tillegalreturntype.nim(11, 11) Error: return type 'typed' is only valid for macros and templates +tillegalreturntype.nim(14, 11) Error: return type 'untyped' is only valid for macros and templates +tillegalreturntype.nim(17, 41) Error: return type 'auto' cannot be used in forward declarations +''' """ proc x(): typed = @@ -10,3 +13,9 @@ proc x(): typed = proc y(): untyped = discard + +proc test_proc[T, U](arg1: T, arg2: U): auto + +proc test_proc[T, U](arg1: T, arg2: U): auto = + echo "Proc has been called" + return arg1 / arg2 |