tcheckedfield1.nim 1.1 KB

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