tconvaddr.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. block: # issue #24097
  2. type Foo = distinct int
  3. proc foo(x: var Foo) =
  4. int(x) += 1
  5. proc bar(x: var int) =
  6. x += 1
  7. static:
  8. var x = Foo(1)
  9. int(x) = int(x) + 1
  10. doAssert x.int == 2
  11. int(x) += 1
  12. doAssert x.int == 3
  13. foo(x)
  14. doAssert x.int == 4
  15. bar(int(x)) # need vmgen flags propagated for this
  16. doAssert x.int == 5
  17. type Bar = object
  18. x: Foo
  19. static:
  20. var obj = Bar(x: Foo(1))
  21. int(obj.x) = int(obj.x) + 1
  22. doAssert obj.x.int == 2
  23. int(obj.x) += 1
  24. doAssert obj.x.int == 3
  25. foo(obj.x)
  26. doAssert obj.x.int == 4
  27. bar(int(obj.x)) # need vmgen flags propagated for this
  28. doAssert obj.x.int == 5
  29. static:
  30. var arr = @[Foo(1)]
  31. int(arr[0]) = int(arr[0]) + 1
  32. doAssert arr[0].int == 2
  33. int(arr[0]) += 1
  34. doAssert arr[0].int == 3
  35. foo(arr[0])
  36. doAssert arr[0].int == 4
  37. bar(int(arr[0])) # need vmgen flags propagated for this
  38. doAssert arr[0].int == 5
  39. proc testResult(): Foo =
  40. result = Foo(1)
  41. int(result) = int(result) + 1
  42. doAssert result.int == 2
  43. int(result) += 1
  44. doAssert result.int == 3
  45. foo(result)
  46. doAssert result.int == 4
  47. bar(int(result)) # need vmgen flags propagated for this
  48. doAssert result.int == 5
  49. doAssert testResult().int == 5