teffects16.nim 637 B

123456789101112131415161718192021
  1. discard """
  2. action: compile
  3. errormsg: "writeSomething(\"a\") can have an unlisted effect: WriteIO"
  4. line: 20
  5. """
  6. type
  7. IO = object of RootEffect ## input/output effect
  8. ReadIO = object of IO ## input effect
  9. WriteIO = object of IO ## output effect
  10. LogIO = object of IO ## another output effect
  11. proc readSomething(): string {.tags: [ReadIO].} = ""
  12. proc writeSomething(msg: string): void {.tags: [WriteIO].} = echo msg
  13. proc logSomething(msg: string): void {.tags: [LogIo].} = echo msg
  14. proc noWritesPlease() {.forbids: [WriteIO], tags: [LogIO, ReadIO].} =
  15. echo readSomething()
  16. logSomething("a")
  17. writeSomething("a")