tbaddeprecated.nim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. discard """
  2. output: '''
  3. not deprecated
  4. not deprecated
  5. not error
  6. not error
  7. '''
  8. """
  9. # issue #21724
  10. block: # deprecated
  11. {.push warningAsError[Deprecated]: on.}
  12. type
  13. SomeObj = object
  14. hey: bool
  15. proc hey() {.deprecated: "Shouldn't use this".} = echo "hey"
  16. proc gen(o: auto) =
  17. doAssert not compiles(o.hey())
  18. if o.hey:
  19. echo "not deprecated"
  20. gen(SomeObj(hey: true))
  21. doAssert not (compiles do:
  22. proc hey(o: SomeObj) {.deprecated: "Shouldn't use this".} = echo "hey"
  23. proc gen2(o: auto) =
  24. if o.hey():
  25. echo "not deprecated"
  26. gen2(SomeObj(hey: true)))
  27. proc hey(o: SomeObj) {.deprecated: "Shouldn't use this".} = echo "hey"
  28. proc gen3(o: auto) =
  29. if o.hey:
  30. echo "not deprecated"
  31. gen3(SomeObj(hey: true))
  32. {.pop.}
  33. block: # error
  34. type
  35. SomeObj = object
  36. hey: bool
  37. proc hey() {.error: "Shouldn't use this".} = echo "hey"
  38. proc gen(o: auto) =
  39. doAssert not compiles(o.hey())
  40. if o.hey:
  41. echo "not error"
  42. gen(SomeObj(hey: true))
  43. doAssert not (compiles do:
  44. proc hey(o: SomeObj) {.error: "Shouldn't use this".} = echo "hey"
  45. proc gen2(o: auto) =
  46. if o.hey():
  47. echo "not error"
  48. gen2(SomeObj(hey: true)))
  49. proc hey(o: SomeObj) {.error: "Shouldn't use this".} = echo "hey"
  50. proc gen3(o: auto) =
  51. if o.hey:
  52. echo "not error"
  53. gen3(SomeObj(hey: true))