sqlite-simple icon indicating copy to clipboard operation
sqlite-simple copied to clipboard

Literal overflow in tests

Open Shimuuar opened this issue 8 years ago • 1 comments

Tests for parameter conversion have some strange statements:

  [Only r] <- (query conn "SELECT ?" (Only (1 :: Int8))) :: IO [Only Int]
  assertEqual "value" 1 r
  [Only r] <- (query conn "SELECT ?" (Only (257 :: Int8))) :: IO [Only Int] -- wrap around
  assertEqual "value" 1 r

But those tests are literally same since (257 :: Int8) == (1 :: int8). So it's not clear what exactly they test

*Main Data.Int> (257 :: Int8) == (1 :: Int8)
<interactive>:9:2: Warning:
    Literal 257 is out of the Int8 range -128..127
True
``

Shimuuar avatar Jun 23 '16 21:06 Shimuuar

If the wraparound were not happening in GHC during compilation, then it would be testing run-time down-casting by fromIntegral.

But the wraparound/down-casting is happening at compile-time, so these wraparound tests seem pointless. I can't think of what else they are for. Maybe they should be removed, but perhaps the test can be done by SELECTing from actual tables with rows with uncasted large integral values to test the run-time casting.

jchia avatar Jan 14 '24 13:01 jchia