Appended code is a cutdown from
While the code seem obfuscated, it should be legal, resulting in
It seems, that Iverilog makes wrong assumptions about the required width. Here the result of the ? operator could even be negative, up to -4.
> env LANG=C iverilog use_wid.v
use_wid.v:4: assert: elab_expr.cc:2765: failed assertion use_wid > 0
sh: line 1: 29359 Done /usr/local/lib/ivl/ivlpp -L -F/tmp/ivrlg23746e16f -f/tmp/ivrlg3746e16f -p/tmp/ivrli3746e16f
29360 Aborted | /usr/local/lib/ivl/ivl -C/tmp/ivrlh3746e16f -C/usr/local/lib/ivl/vvp.conf -- -