.forbids pragma: defining forbidden tags (#20050)
* .forbids pragma: defining illegal effects for proc types This patch intends to define the opposite of the .tags pragma: a way to define effects which are not allowed in a proc. * updated documentation and changelogs for the forbids pragma * renamed notTagEffects to forbiddenEffects * corrected issues of forbids pragma the forbids pragma didn't handle simple restrictions properly and it also had issues with subtyping * removed incorrect character from changelog * added test to cover the interaction of methods and the forbids pragma * covering the interaction of the tags and forbids pragmas * updated manual about the forbids pragma * removed useless statement * corrected the subtyping of proc types using the forbids pragma * updated manual for the forbids pragma * updated documentations for forbids pragma * updated nim docs * updated docs with rsttester.nim * regenerated documentation * updated rst docs * Update changelog.md Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> * updated changelog * corrected typo Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
parent
62b81d7f10
commit
efd5c571bf
24 changed files with 405 additions and 71 deletions
23
tests/effects/teffects19.nim
Normal file
23
tests/effects/teffects19.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
discard """
|
||||
action: compile
|
||||
errormsg: "type mismatch: got <proc (i: int){.gcsafe, locks: 0.}>"
|
||||
line: 23
|
||||
"""
|
||||
|
||||
type MyEffect = object
|
||||
type ProcType1 = proc (i: int): void {.forbids: [MyEffect].}
|
||||
type ProcType2 = proc (i: int): void
|
||||
|
||||
proc caller1(p: ProcType1): void = p(1)
|
||||
proc caller2(p: ProcType2): void = p(1)
|
||||
|
||||
proc effectful(i: int): void {.tags: [MyEffect].} = echo $i
|
||||
proc effectless(i: int): void {.forbids: [MyEffect].} = echo $i
|
||||
|
||||
proc toBeCalled1(i: int): void = effectful(i)
|
||||
proc toBeCalled2(i: int): void = effectless(i)
|
||||
|
||||
caller1(toBeCalled2)
|
||||
caller2(toBeCalled1)
|
||||
caller2(toBeCalled2)
|
||||
caller1(toBeCalled1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue