bsc crash when bs method arg name annotation doesn't match method arity
#420 opened on Oct 2, 2021
Repository metrics
- Stars
- (1,108 stars)
- PR merge metrics
- (Avg merge 17d 1h) (18 merged PRs in 30d)
Description
if the arg_names annotation in a classic interface declaration has fewer names than the method has arguments, bsc crashes without any useful information:
bsc -verilog BugMethodArgNamesArity.bs
Prelude.!!: index too large
BugMethodArgNamesArity.bs is:
package BugMethodArgNamesArity where
interface ArityBug =
foo :: Bool -> Bool -> Action {-# arg_names = [bar] #-}
{-# verilog mkArityBug #-}
mkArityBug :: Module ArityBug
mkArityBug = module
interface
foo _ _ = _
this specific crash occurs when !! is used in the definition of i' inside iExpandMethodLam at IExpand.hs:1065, although at least the !! in the definition of m_origion_type below has the exact same problem.
iirc the IExpand state monad handles errors, so it should be possible to check in iExpandMethodLam and emit a more informative error with a reasonable position; failing that, a quick-hack ICE with a position would also work.