Open kleinreact opened 1 year ago
GHC is able to do this for builtin types:
GHCi, version 9.6.2: https://www.haskell.org/ghc/ :? for help
ghci> import Data.Word
ghci> x = 256 :: Word8
<interactive>:2:5: warning: [GHC-97441] [-Woverflowed-literals]
Literal 256 is out of the Word8 range 0..255
And only in a monomorphic setting:
ghci> y = 256
ghci> z = y :: Word8
ghci> -- no warning
ghci> y
256
ghci> z
0
ghci>
ghci> :t y
y :: Num a => a
ghci> :t z
z :: Word8
The following example compiles without errors / warnings and does not wrap the used out-of-range constant:
The produced verilog, however, produces a warning on most simulators / synthesizers. Hence, it may be a good idea to produce a warning in Clash as well.
Questa
iVerilog (v12.0)
Yosys (v0.31)
Verilator (v5.002 2022-10-29)