B-Lang-org/bsc

bsc crash when bs method arg name annotation doesn't match method arity

Open

#420 opened on Oct 2, 2021

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Haskell (1,108 stars) (178 forks)batch import
ICEerror-messagesgood first issue

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.

Contributor guide