t14383.nim 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. discard """
  2. cmd: "nim c --gc:arc $file"
  3. output: '''
  4. hello
  5. hello
  6. @["a", "b"]
  7. ---------------------
  8. plain:
  9. destroying: ('first', 42)
  10. destroying: ('second', 20)
  11. destroying: ('third', 12)
  12. Option[T]:
  13. destroying: ('first', 42)
  14. destroying: ('second', 20)
  15. destroying: ('third', 12)
  16. seq[T]:
  17. destroying: ('first', 42)
  18. destroying: ('second', 20)
  19. destroying: ('third', 12)
  20. 1 1
  21. '''
  22. """
  23. import dmodule
  24. var val = parseMinValue()
  25. if val.kind == minDictionary:
  26. echo val
  27. #------------------------------------------------------------------------------
  28. # Issue #15238
  29. #------------------------------------------------------------------------------
  30. proc sinkArg(x: sink seq[string]) =
  31. discard
  32. proc varArg(lst: var seq[string]) =
  33. sinkArg(lst)
  34. var x = @["a", "b"]
  35. varArg(x)
  36. echo x
  37. #------------------------------------------------------------------------------
  38. # Issue #15286
  39. #------------------------------------------------------------------------------
  40. import std/os
  41. discard getFileInfo(".")
  42. #------------------------------------------------------------------------------
  43. # Issue #15707
  44. #------------------------------------------------------------------------------
  45. type
  46. JVMObject = ref object
  47. proc freeJVMObject(o: JVMObject) =
  48. discard
  49. proc fromJObject(T: typedesc[JVMObject]): T =
  50. result.new(cast[proc(r: T) {.nimcall.}](freeJVMObject))
  51. discard JVMObject.fromJObject()
  52. #------------------------------------------------------------------------------
  53. # Issue #15910
  54. #------------------------------------------------------------------------------
  55. import options
  56. type
  57. Thing = object
  58. name: string
  59. age: int
  60. proc `=destroy`(thing: var Thing) =
  61. if thing.name != "":
  62. echo "destroying: ('", thing.name, "', ", thing.age, ")"
  63. `=destroy`(thing.name)
  64. `=destroy`(thing.age)
  65. proc plain() =
  66. var t = Thing(name: "first", age: 42)
  67. t = Thing(name: "second", age: 20)
  68. t = Thing()
  69. let u = Thing(name: "third", age: 12)
  70. proc optionT() =
  71. var t = Thing(name: "first", age: 42).some
  72. t = Thing(name: "second", age: 20).some
  73. t = none(Thing)
  74. let u = Thing(name: "third", age: 12).some
  75. proc seqT() =
  76. var t = @[Thing(name: "first", age: 42)]
  77. t = @[Thing(name: "second", age: 20)]
  78. t = @[]
  79. let u = @[Thing(name: "third", age: 12)]
  80. echo "---------------------"
  81. echo "plain:"
  82. plain()
  83. echo()
  84. echo "Option[T]:"
  85. optionT()
  86. echo()
  87. echo "seq[T]:"
  88. seqT()
  89. echo()
  90. #------------------------------------------------------------------------------
  91. # Issue #16120, const seq into sink
  92. #------------------------------------------------------------------------------
  93. proc main =
  94. let avals = @[@[1.0'f32, 4.0, 7.0, 10.0]]
  95. let rankdef = avals
  96. echo avals.len, " ", rankdef.len
  97. main()