timplictderef.nim 441 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''2
  3. 88'''
  4. """
  5. type
  6. TValue* {.pure, final.} = object of RootObj
  7. a: int
  8. PValue = ref TValue
  9. PPValue = ptr PValue
  10. var x: PValue
  11. new x
  12. var sp: PPValue = addr x
  13. sp.a = 2
  14. if sp.a == 2: echo 2 # with sp[].a the error is gone
  15. # Test the new auto-deref a little
  16. {.experimental.}
  17. proc p(x: var int; y: int) = x += y
  18. block:
  19. var x: ref int
  20. new(x)
  21. x.p(44)
  22. var indirect = p
  23. x.indirect(44)
  24. echo x[]