tunsignedmisc.nim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. discard """
  2. errormsg: "number out of range: '0x123'u8'"
  3. """
  4. # Bug #1179
  5. # Unsigneds
  6. # 8 bit
  7. let ref1 = 128'u8 shr 7
  8. let hex1 = 0x80'u8 shr 7
  9. let oct1 = 0o200'u8 shr 7
  10. let dig1 = 0b10000000'u8 shr 7
  11. doAssert(ref1 == 1)
  12. doAssert(ref1 == hex1)
  13. doAssert(ref1 == oct1)
  14. doAssert(ref1 == dig1)
  15. # 16 bit
  16. let ref2 = 32768'u16 shr 15
  17. let hex2 = 0x8000'u16 shr 15
  18. let oct2 = 0o100000'u16 shr 15
  19. let dig2 = 0b1000000000000000'u16 shr 15
  20. doAssert(ref2 == 1)
  21. doAssert(ref2 == hex2)
  22. doAssert(ref2 == oct2)
  23. doAssert(ref2 == dig2)
  24. # 32 bit
  25. let ref3 = 2147483648'u32 shr 31
  26. let hex3 = 0x80000000'u32 shr 31
  27. let oct3 = 0o20000000000'u32 shr 31
  28. let dig3 = 0b10000000000000000000000000000000'u32 shr 31
  29. doAssert(ref3 == 1)
  30. doAssert(ref3 == hex3)
  31. doAssert(ref3 == oct3)
  32. doAssert(ref3 == dig3)
  33. # Below doesn't work for lexer stage errors...
  34. # doAssert(compiles(0xFF'u8) == true)
  35. # doAssert(compiles(0xFFF'u16) == true)
  36. # doAssert(compiles(0x7FFF'i16) == true)
  37. # doAssert(compiles(0x123'u8) == false)
  38. # doAssert(compiles(0x123'i8) == false)
  39. # doAssert(compiles(0x123123'u16) == false)
  40. # doAssert(compiles(0x123123'i16) == false)
  41. # Should compile #
  42. let boundOkHex1 = 0xFF'u8
  43. let boundOkHex2 = 0xFFFF'u16
  44. let boundOkHex3 = 0x7FFF'i16
  45. let boundOkHex4 = 0x80'i8
  46. let boundOkHex5 = 0xFF'i8
  47. let boundOkHex6 = 0xFFFF'i16
  48. let boundOkHex7 = 0x7FFF'i16
  49. # Should _not_ compile #
  50. let boundBreakingHex1 = 0x123'u8
  51. let boundBreakingHex2 = 0x123'i8
  52. let boundBreakingHex3 = 0x123123'u16
  53. let boundBreakingHex4 = 0x123123'i16