twarningaserror.nim 751 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. joinable: false
  3. """
  4. #[
  5. tests: hintAsError, warningAsError
  6. ]#
  7. template fn1 =
  8. {.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
  9. proc fn(a: string) = discard a.string
  10. {.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
  11. template fn2 =
  12. {.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
  13. proc fn(a: string) = discard a
  14. {.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
  15. template gn1 =
  16. {.warningAsError[ProveInit]:on.}
  17. proc fn(): var int = discard
  18. discard fn()
  19. {.warningAsError[ProveInit]:off.}
  20. template gn2 =
  21. {.warningAsError[ProveInit]:on.}
  22. proc fn(): int = discard
  23. discard fn()
  24. {.warningAsError[ProveInit]:off.}
  25. doAssert not compiles(fn1())
  26. doAssert compiles(fn2())
  27. doAssert not compiles(gn1())
  28. doAssert compiles(gn2())