tlent_var.nim 385 B

1234567891011121314151617181920212223242526
  1. discard """
  2. output: ''''''
  3. """
  4. type
  5. MyObj = object
  6. a: int
  7. proc test_lent(x: MyObj): lent int =
  8. x.a
  9. proc test_var(x: var MyObj): var int =
  10. x.a
  11. var x = MyObj(a: 5)
  12. doAssert: test_var(x).addr == x.a.addr
  13. doAssert: test_lent(x).addr == x.a.addr
  14. proc varProc(x: var int) =
  15. x = 100
  16. doAssert: not compiles(test_lent(x) = 1)
  17. doAssert: not compiles(varProc(test_lent(x)))