diff options
author | zah <zahary@gmail.com> | 2017-03-12 10:33:49 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-03-12 09:33:49 +0100 |
commit | 1be0022e7c6a8d168918998fd27412901432075d (patch) | |
tree | 64be855cb15ffb466098e33b526799a6aa49a9c7 /tests/errmsgs | |
parent | 6e358e318747ecd6bea66911d6144cb7eff9d172 (diff) | |
download | Nim-1be0022e7c6a8d168918998fd27412901432075d.tar.gz |
Fixes #5167 and related problems (#5475)
This commit returns to a bit less strict checking of the number of macro arguments, because some old immediate macros rely on a behavior where even the arity of the macro is not being checked. It may be better if such macros are just declared to use varargs[expr], but this remains for another day.
Diffstat (limited to 'tests/errmsgs')
-rw-r--r-- | tests/errmsgs/t5167_1.nim | 17 | ||||
-rw-r--r-- | tests/errmsgs/t5167_2.nim | 12 | ||||
-rw-r--r-- | tests/errmsgs/t5167_3.nim | 25 | ||||
-rw-r--r-- | tests/errmsgs/t5167_4.nim | 20 | ||||
-rw-r--r-- | tests/errmsgs/t5167_5.nim | 25 |
5 files changed, 99 insertions, 0 deletions
diff --git a/tests/errmsgs/t5167_1.nim b/tests/errmsgs/t5167_1.nim new file mode 100644 index 000000000..9f4f208a4 --- /dev/null +++ b/tests/errmsgs/t5167_1.nim @@ -0,0 +1,17 @@ +discard """ +errormsg: "'bar' doesn't have a concrete type, due to unspecified generic parameters." +line: 16 +""" + +proc foo[T]() = + var y1 = foo[string] + var y2 = foo[T] + +proc bar[T]() = + let x = 0 + +let good1 = foo[int] +let good2 = bar[int] + +let err = bar + diff --git a/tests/errmsgs/t5167_2.nim b/tests/errmsgs/t5167_2.nim new file mode 100644 index 000000000..17d96ef47 --- /dev/null +++ b/tests/errmsgs/t5167_2.nim @@ -0,0 +1,12 @@ +discard """ +cmd: "nim c --threads:on $file" +errormsg: "'threadFunc' doesn't have a concrete type, due to unspecified generic parameters." +line: 11 +""" + +proc threadFunc[T]() {.thread.} = + let x = 0 + +var thr: Thread[void] +thr.createThread(threadFunc) + diff --git a/tests/errmsgs/t5167_3.nim b/tests/errmsgs/t5167_3.nim new file mode 100644 index 000000000..2781d3943 --- /dev/null +++ b/tests/errmsgs/t5167_3.nim @@ -0,0 +1,25 @@ +discard """ +cmd: "nim c --threads:on $file" +errormsg: "type mismatch" +line: 24 +""" + +type + TGeneric[T] = object + x: int + +proc foo1[A, B, C, D](x: proc (a: A, b: B, c: C, d: D)) = + echo "foo1" + +proc foo2(x: proc(x: int)) = + echo "foo2" + +# The goal of this test is to verify that none of the generic parameters of the +# proc will be marked as unused. The error message should be "type mismatch" instead +# of "'bar' doesn't have a concrete type, due to unspecified generic parameters". +proc bar[A, B, C, D](x: A, y: seq[B], z: array[4, TGeneric[C]], r: TGeneric[D]) = + echo "bar" + +foo1[int, seq[int], array[4, TGeneric[float]], TGeneric[string]] bar +foo2 bar + diff --git a/tests/errmsgs/t5167_4.nim b/tests/errmsgs/t5167_4.nim new file mode 100644 index 000000000..3d77fae02 --- /dev/null +++ b/tests/errmsgs/t5167_4.nim @@ -0,0 +1,20 @@ +discard """ +errormsg: "type mismatch: got (proc [*missing parameters*](x: int) | proc (x: string){.gcsafe, locks: 0.})" +line: 19 +""" + +type + TGeneric[T] = object + x: int + +proc foo[B](x: int) = + echo "foo1" + +proc foo(x: string) = + echo "foo2" + +proc bar(x: proc (x: int)) = + echo "bar" + +bar foo + diff --git a/tests/errmsgs/t5167_5.nim b/tests/errmsgs/t5167_5.nim new file mode 100644 index 000000000..ab02f29f6 --- /dev/null +++ b/tests/errmsgs/t5167_5.nim @@ -0,0 +1,25 @@ +discard """ +cmd: "nim check $file" +errormsg: "'m' has unspecified generic parameters" +nimout: ''' +t5167_5.nim(20, 9) Error: 't' has unspecified generic parameters +t5167_5.nim(21, 5) Error: 't' has unspecified generic parameters +t5167_5.nim(23, 9) Error: 'm' has unspecified generic parameters +t5167_5.nim(24, 5) Error: 'm' has unspecified generic parameters +''' +""" + +template t[B]() = + echo "foo1" + +macro m[T]: stmt = nil + +proc bar(x: proc (x: int)) = + echo "bar" + +let x = t +bar t + +let y = m +bar m + |