tnot_allowed_lent.nim 538 B

12345678910111213141516171819202122232425
  1. discard """
  2. errormsg: "expression has no address"
  3. """
  4. type
  5. MyObject = object
  6. x: seq[string]
  7. proc mytest1(s: MyObject, i: int): lent string =
  8. ## works fine
  9. if i < s.x.len - 1 and s.x[i] != "":
  10. result = s.x[i]
  11. else: raise newException(KeyError, "err1")
  12. proc mytest2(s: MyObject, i: int): lent string =
  13. ## reject due to if expr
  14. if i < s.x.len - 1 and s.x[i] != "": s.x[i]
  15. else: raise newException(KeyError, "err1")
  16. for i in 1..5:
  17. var x = MyObject(x: @["1", "2", "3"])
  18. echo mytest1(x, 1)
  19. echo mytest2(x, 1)