Cannot coerce expression error while compiling spicy script

=== STDERR ===

====================| Spicy-side Zeek Installation Summary |====================

Found Zeek: yes

Version: 6.0.0 (60000)
Prefix: /usr/local/zeek
Build type: relwithdebinfo

========================================================================

====================| Spicy Installation Summary |====================

Found Spicy: yes

Version: 1.9.0-dev.157 (d26c81c0) (10900)
Prefix: /mnt/zeek/broker
Build type: release
Have toolchain: yes
Spicy compiler: /mnt/zeek/broker/bin/spicyc

========================================================================

[error] /mnt/zeek/broker/var/lib/zkg/testing/zeek-iec104/clones/zeek-iec104/analyzer/iec104.spicy:743:5: cannot coerce expression ‘(0, asdu.info_obj_addr, asdu.siq)’ of type ‘tuple<uint<64>, uint<64>, bitfield(8) { spi: 0; bl: 4; sb: 5; nt: 6; iv: 7; }>’ to type ‘tuple<uint<64>, uint<64>, tuple<spi: uint<8>, bl: uint<8>, sb: uint<8>, nt: uint<8>, iv: uint<8>>>’
[error] /mnt/zeek/broker/var/lib/zkg/testing/zeek-iec104/clones/zeek-iec104/analyzer/iec104.spicy:747:5: cannot coerce expression ‘(0, asdu.info_obj_addr, asdu.sco)’ of type ‘tuple<uint<64>, uint<64>, bitfield(8) { sco_on: 0; qu: 2…6; se: 7; }>’ to type ‘tuple<uint<64>, uint<64>, tuple<sco_on: uint<8>, qu: uint<8>, se: uint<8>>>’

Any idea how to fix this issue? It was not coming in earlier spicy versions.

Thanks
Biswa

It would have been good had you included the actual code in this, but I assume from the error string that your issues was with this package. The origin of the error message you posted seems to be in code like this:

public function SIQ_ret (asdu: SIQ) : tuple<uint64, uint64, tuple<spi: uint8, bl: uint8, sb: uint8, nt: uint8, iv: uint8>> {
    return (0, asdu.info_obj_addr, asdu.siq);
}

In this case asdu.siq is declared like this:

    siq : bitfield(8) { 
        spi : 0;
        bl : 4;
        sb : 5;
        nt : 6;
        iv : 7;
    };

The issue with SIQ_ret is that it assumes that a bitfield can implicitly convert to a tuple. This is not the case and if at all worked only by accident in the past. The correct approach would be to do the conversion by hand, with the intended semantics.

@Benjamin_Bannier Thanks a lot for the suggestion.

Surprisingly the issue is not coming when using below versions.

root# /usr/local/zeek/bin/spicyc -v

spicyc v1.8.1

root# /usr/local/zeek/bin/zeek -v

/usr/local/zeek/bin/zeek version 6.0.0