tcheckedfield1.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. discard """
  2. nimout: "Warning: cannot prove that field 'x.s' is accessible [ProveField]"
  3. line:51
  4. action: run
  5. output: "abc abc"
  6. """
  7. import strutils
  8. {.warning[ProveField]: on.}
  9. {.experimental: "notnil".}
  10. type
  11. TNodeKind = enum
  12. nkBinary, nkTernary, nkStr
  13. PNode = ref TNode not nil
  14. TNode = object
  15. case k: TNodeKind
  16. of nkBinary, nkTernary: a, b: PNode
  17. of nkStr: s: string
  18. PList = ref object
  19. data: string
  20. next: PList
  21. proc getData(x: PList not nil) =
  22. echo x.data
  23. var head: PList
  24. proc processList() =
  25. var it = head
  26. while it != nil:
  27. getData(it)
  28. it = it.next
  29. proc toString2(x: PNode): string =
  30. if x.k < nkStr:
  31. toString2(x.a) & " " & toString2(x.b)
  32. else:
  33. x.s
  34. proc toString(x: PNode): string =
  35. case x.k
  36. of nkTernary, nkBinary:
  37. toString(x.a) & " " & toString(x.b)
  38. of nkStr:
  39. x.s
  40. proc toString3(x: PNode): string =
  41. if x.k <= nkBinary:
  42. toString3(x.a) & " " & toString3(x.b)
  43. else:
  44. x.s # x.k in {nkStr} --> fact: not (x.k <= nkBinary)
  45. proc p() =
  46. var x: PNode = PNode(k: nkStr, s: "abc")
  47. let y = x
  48. if not y.isNil:
  49. echo toString(y), " ", toString2(y)
  50. p()