trefbyvar.nim 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. discard """
  2. output: '''0
  3. 5
  4. 0
  5. 5
  6. @[1, 2]
  7. ~'''
  8. """
  9. # bug #2476
  10. type A = ref object
  11. m: int
  12. proc f(a: var A) =
  13. var b: A
  14. b.new()
  15. b.m = 5
  16. a = b
  17. var t: A
  18. t.new()
  19. echo t.m
  20. t.f()
  21. echo t.m
  22. proc main =
  23. # now test the same for locals
  24. var t: A
  25. t.new()
  26. echo t.m
  27. t.f()
  28. echo t.m
  29. main()
  30. # bug #5974
  31. type
  32. View* = object
  33. data: ref seq[int]
  34. let a = View(data: new(seq[int]))
  35. a.data[] = @[1, 2]
  36. echo a.data[]
  37. # bug #5379
  38. var input = newSeq[ref string]()
  39. input.add(nil)
  40. input.add(new string)
  41. input[1][] = "~"
  42. echo input[1][]
  43. # bug #5517
  44. type
  45. TypeA1 = object of RootObj
  46. a_impl: int
  47. b_impl: string
  48. c_impl: pointer
  49. proc initTypeA1(a: int; b: string; c: pointer = nil): TypeA1 =
  50. result.a_impl = a
  51. result.b_impl = b
  52. result.c_impl = c
  53. let x = initTypeA1(1, "a")
  54. doAssert($x == "(a_impl: 1, b_impl: \"a\", c_impl: ...)")