diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/proc/tunderscoreparam.nim | 13 | ||||
-rw-r--r-- | tests/stmt/tforloop_tuple_multiple_underscore.nim | 4 | ||||
-rw-r--r-- | tests/stmt/tforloop_tuple_underscore.nim | 2 | ||||
-rw-r--r-- | tests/stmt/tforloop_underscore.nim | 2 | ||||
-rw-r--r-- | tests/stmt/tgenericsunderscore.nim | 4 | ||||
-rw-r--r-- | tests/stmt/tmiscunderscore.nim | 15 | ||||
-rw-r--r-- | tests/template/tunderscore1.nim | 2 |
7 files changed, 37 insertions, 5 deletions
diff --git a/tests/proc/tunderscoreparam.nim b/tests/proc/tunderscoreparam.nim index c2f6cf8ad..8d60603f1 100644 --- a/tests/proc/tunderscoreparam.nim +++ b/tests/proc/tunderscoreparam.nim @@ -79,6 +79,19 @@ proc test() = proc foo(_: int) = let a = _ doAssert not compiles(main()) + + block: # generic params + doAssert not (compiles do: + proc foo[_](t: typedesc[_]): seq[_] = @[default(_)] + doAssert foo[int]() == 0) + + block: + proc foo[_, _](): int = 123 + doAssert foo[int, bool]() == 123 + + block: + proc foo[T; U](_: typedesc[T]; _: typedesc[U]): (T, U) = (default(T), default(U)) + doAssert foo(int, bool) == (0, false) proc closureTest() = var x = 0 diff --git a/tests/stmt/tforloop_tuple_multiple_underscore.nim b/tests/stmt/tforloop_tuple_multiple_underscore.nim index 2afdb0b77..96804df18 100644 --- a/tests/stmt/tforloop_tuple_multiple_underscore.nim +++ b/tests/stmt/tforloop_tuple_multiple_underscore.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "undeclared identifier: '_'" + errormsg: "the special identifier '_' is ignored in declarations and cannot be used" """ iterator iter(): (int, int, int) = @@ -7,4 +7,4 @@ iterator iter(): (int, int, int) = for (_, i, _) in iter(): - echo _ \ No newline at end of file + echo _ diff --git a/tests/stmt/tforloop_tuple_underscore.nim b/tests/stmt/tforloop_tuple_underscore.nim index 8cbb0fc10..eda42d527 100644 --- a/tests/stmt/tforloop_tuple_underscore.nim +++ b/tests/stmt/tforloop_tuple_underscore.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "undeclared identifier: '_'" + errormsg: "the special identifier '_' is ignored in declarations and cannot be used" """ iterator iter(): (int, int) = diff --git a/tests/stmt/tforloop_underscore.nim b/tests/stmt/tforloop_underscore.nim index c5b49da77..ce1c86386 100644 --- a/tests/stmt/tforloop_underscore.nim +++ b/tests/stmt/tforloop_underscore.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "undeclared identifier: '_'" + errormsg: "the special identifier '_' is ignored in declarations and cannot be used" """ for _ in ["a"]: diff --git a/tests/stmt/tgenericsunderscore.nim b/tests/stmt/tgenericsunderscore.nim new file mode 100644 index 000000000..be2b8ec78 --- /dev/null +++ b/tests/stmt/tgenericsunderscore.nim @@ -0,0 +1,4 @@ +# issue #21435 + +proc foo[_](x: typedesc[_]): string = "BAR" #[tt.Error + ^ the special identifier '_' is ignored in declarations and cannot be used]# diff --git a/tests/stmt/tmiscunderscore.nim b/tests/stmt/tmiscunderscore.nim new file mode 100644 index 000000000..c4bae1c3d --- /dev/null +++ b/tests/stmt/tmiscunderscore.nim @@ -0,0 +1,15 @@ +import std/assertions + +block: + proc _() = echo "one" + doAssert not compiles(_()) + proc _() = echo "two" + doAssert not compiles(_()) + +block: + type _ = int + doAssert not (compiles do: + let x: _ = 3) + type _ = float + doAssert not (compiles do: + let x: _ = 3) diff --git a/tests/template/tunderscore1.nim b/tests/template/tunderscore1.nim index 71af39501..d74e5ba63 100644 --- a/tests/template/tunderscore1.nim +++ b/tests/template/tunderscore1.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "undeclared identifier: '_'" + errormsg: "the special identifier '_' is ignored in declarations and cannot be used" """ # issue #12094, #13804 |