t8404.nim 586 B

12345678910111213141516171819202122232425262728293031323334
  1. discard """
  2. targets: "c cpp js"
  3. """
  4. template main() =
  5. block: # bug #8404
  6. # can conv
  7. template float2int(T) =
  8. var a = -1.0
  9. let b = T(a)
  10. doAssert b < 0
  11. let c = b + 1
  12. doAssert c is T
  13. doAssert c == 0
  14. float2int(int8)
  15. float2int(int16)
  16. float2int(int32)
  17. float2int(int64)
  18. block:
  19. # can handle middle conv
  20. # `/` can trigger int to float
  21. template float2int(T) =
  22. let n = T(1 / 256)
  23. doAssert n == 0
  24. float2int(int8)
  25. float2int(int16)
  26. float2int(int32)
  27. # float2int(int64)
  28. main()
  29. static:
  30. main()