tlent_from_var.nim 498 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. output: '''x
  3. [10, 11, 12, 13]'''
  4. """
  5. # bug #14805
  6. type Foo = object
  7. a: string
  8. proc bar(f: var Foo): lent string =
  9. result = f.a
  10. var foo = Foo(a: "x")
  11. echo bar(foo)
  12. # bug #14878
  13. # proc byLentImpl[T](a: T): lent T = a
  14. proc byLentVar[T](a: var T): lent T =
  15. result = a
  16. # result = a.byLentImpl # this doesn't help
  17. var x = 3 # error: cannot take the address of an rvalue of type 'NI *'
  18. var xs = [10,11,12,13] # SIGSEGV
  19. let x2 = x.byLentVar
  20. let xs2 = xs.byLentVar
  21. echo xs2