diff options
author | metagn <metagngn@gmail.com> | 2023-04-13 13:50:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 12:50:43 +0200 |
commit | c694d8e4fd6a14ab6a79fe6359033a4be6133b8c (patch) | |
tree | 954b1115667abddf400921f245bd447d3cb90eef /tests/pragmas | |
parent | 16f42084d32144d5afb2a5cc3a5a833e5295a8bc (diff) | |
download | Nim-c694d8e4fd6a14ab6a79fe6359033a4be6133b8c.tar.gz |
custom pragmas: correct error condition, remove outdated symkind whitelist (#21653)
* test not restricting custom pragma applied symbols fixes #21652 * fix other test * different patch * fix tests * actually test #18212 and other routines
Diffstat (limited to 'tests/pragmas')
-rw-r--r-- | tests/pragmas/t8741.nim | 2 | ||||
-rw-r--r-- | tests/pragmas/tcustom_pragma.nim | 29 | ||||
-rw-r--r-- | tests/pragmas/tinvalidcustompragma.nim | 23 |
3 files changed, 52 insertions, 2 deletions
diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim index 221c732b0..bf97b0e29 100644 --- a/tests/pragmas/t8741.nim +++ b/tests/pragmas/t8741.nim @@ -1,7 +1,7 @@ discard """ cmd: "nim check --hint:processing:off $file" errormsg: "3 is not two" - nimout: '''t8741.nim(13, 9) Error: cannot attach a custom pragma to 'a' + nimout: '''t8741.nim(13, 9) Error: invalid pragma: foobar t8741.nim(29, 15) template/generic instantiation of `onlyTwo` from here t8741.nim(25, 12) Error: 3 is not two ''' diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim index ad25cad98..9ffa9a33d 100644 --- a/tests/pragmas/tcustom_pragma.nim +++ b/tests/pragmas/tcustom_pragma.nim @@ -399,12 +399,39 @@ block: discard Hello(a: 1.0, b: 12) -# custom pragma on iterators +# test routines +block: + template prag {.pragma.} + proc hello {.prag.} = discard + iterator hello2: int {.prag.} = discard + template hello3(x: int): int {.prag.} = x + macro hello4(x: int): int {.prag.} = x + func hello5(x: int): int {.prag.} = x + doAssert hello.hasCustomPragma(prag) + doAssert hello2.hasCustomPragma(prag) + doAssert hello3.hasCustomPragma(prag) + doAssert hello4.hasCustomPragma(prag) + doAssert hello5.hasCustomPragma(prag) + +# test push doesn't break block: template prag {.pragma.} {.push prag.} proc hello = discard iterator hello2: int = discard + template hello3(x: int): int = x + macro hello4(x: int): int = x + func hello5(x: int): int = x + type + Foo = enum a + Bar[T] = ref object of RootObj + x: T + case y: bool + of false: discard + else: + when true: discard + for a in [1]: discard a + {.pop.} # issue #11511 when false: diff --git a/tests/pragmas/tinvalidcustompragma.nim b/tests/pragmas/tinvalidcustompragma.nim new file mode 100644 index 000000000..a31695809 --- /dev/null +++ b/tests/pragmas/tinvalidcustompragma.nim @@ -0,0 +1,23 @@ +discard """ + cmd: "nim check $file" +""" + +# issue #21652 +type Foo = object +template foo() {.tags:[Foo].} = #[tt.Error + ^ invalid pragma: tags: [Foo]]# + discard + +{.foobar.} #[tt.Error + ^ invalid pragma: foobar]# +type A = enum a {.foobar.} #[tt.Error + ^ invalid pragma: foobar]# +for b {.foobar.} in [1]: discard #[tt.Error + ^ invalid pragma: foobar]# +template foobar {.pragma.} +{.foobar.} #[tt.Error + ^ cannot attach a custom pragma to 'tinvalidcustompragma'; custom pragmas are not supported for modules]# +type A = enum a {.foobar.} #[tt.Error + ^ cannot attach a custom pragma to 'a'; custom pragmas are not supported for enum fields]# +for b {.foobar.} in [1]: discard #[tt.Error + ^ cannot attach a custom pragma to 'b'; custom pragmas are not supported for `for` loop variables]# |