# Cannot coerce expression error while compiling spicy script

**URL:** <https://community.zeek.org/t/cannot-coerce-expression-error-while-compiling-spicy-script/7227>\
**Category:** Spicy\
**Created:** [December 9, 2023, 1:57pm UTC](https://community.zeek.org/t/cannot-coerce-expression-error-while-compiling-spicy-script/7227 "2023-12-09T13:57:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![biswa61](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@biswa61](https://community.zeek.org/u/biswa61)\
**Post date:** [December 9, 2023, 1:57pm UTC](https://community.zeek.org/t/cannot-coerce-expression-error-while-compiling-spicy-script/7227/1 "2023-12-09T13:57:33Z")

</div>

=== 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

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bannier](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/benjamin_bannier/32/595_2.png) [@Benjamin\_Bannier](https://community.zeek.org/u/Benjamin_Bannier)\
**Post date:** [December 9, 2023, 3:59pm UTC](https://community.zeek.org/t/cannot-coerce-expression-error-while-compiling-spicy-script/7227/2 "2023-12-09T15:59:58Z")

</div>

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](https://github.com/georgemakrakis/zeek-iec104). The origin of the error message you posted seems to be in code like [this](https://github.com/georgemakrakis/zeek-iec104/blob/90d1d3249d404b27ba921ab4bd8f478718162fd0/analyzer/iec104.spicy#L742-L744):

```ruby
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](https://github.com/georgemakrakis/zeek-iec104/blob/90d1d3249d404b27ba921ab4bd8f478718162fd0/analyzer/iec104.spicy#L162-L168):

```ruby
    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.

---

<div class="post-metadata">

**Author:** ![biswa61](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@biswa61](https://community.zeek.org/u/biswa61)\
**Post date:** [December 19, 2023, 12:46pm UTC](https://community.zeek.org/t/cannot-coerce-expression-error-while-compiling-spicy-script/7227/3 "2023-12-19T12:46:39Z")

</div>

@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
