t16076.nim 614 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. discard """
  2. targets: "c js"
  3. """
  4. proc main() =
  5. block: # bug #17485
  6. type
  7. O = ref object
  8. i: int
  9. iterator t(o: O): int =
  10. if o != nil:
  11. yield o.i
  12. yield 0
  13. proc m =
  14. var data = ""
  15. for i in t(nil):
  16. data.addInt i
  17. doAssert data == "0"
  18. m()
  19. block: # bug #16076
  20. type
  21. R = ref object
  22. z: int
  23. var data = ""
  24. iterator foo(x: int; y: R = nil): int {.inline.} =
  25. if y == nil:
  26. yield x
  27. else:
  28. yield y.z
  29. for b in foo(10):
  30. data.addInt b
  31. doAssert data == "10"
  32. static: main()
  33. main()