tunsignedinc.nim 659 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. block: # bug #2427
  2. var x = 0'u8
  3. dec x # OverflowDefect
  4. x -= 1 # OverflowDefect
  5. x = x - 1 # No error
  6. doAssert(x == 253'u8)
  7. block:
  8. var x = 130'u8
  9. x += 130'u8
  10. doAssert(x == 4'u8)
  11. block:
  12. var x = 40000'u16
  13. x = x + 40000'u16
  14. doAssert(x == 14464'u16)
  15. block:
  16. var x = 4000000000'u32
  17. x = x + 4000000000'u32
  18. doAssert(x == 3705032704'u32)
  19. block:
  20. var x = 123'u16
  21. x -= 125
  22. doAssert(x == 65534'u16)
  23. block t4175:
  24. let i = 0u - 1u
  25. const j = 0u - 1u
  26. doAssert i == j
  27. doAssert j + 1u == 0u
  28. block: # https://forum.nim-lang.org/t/12465#76998
  29. var a: int = 1
  30. var x: uint8 = 1
  31. a.inc(x) # Error: type mismatch
  32. doAssert a == 2