teffects13.nim 500 B

1234567891011121314151617181920
  1. discard """
  2. action: compile
  3. errormsg: "writeSomething() has an illegal effect: WriteIO"
  4. line: 19
  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. proc readSomething(): string {.tags: [ReadIO].} = ""
  11. proc writeSomething(): void {.tags: [WriteIO].} = echo "..."
  12. proc noWritesPlease() {.forbids: [WriteIO].} =
  13. # this is OK:
  14. echo readSomething()
  15. # the compiler prevents this:
  16. writeSomething()