I'm assuming it's not possible to handle implement Decode for tagged unions without some form of a macro system. Have there been any previous discussions of this? It does feel a bit incomplete for this to be missing
it's possible, we just haven't implemented it
it shouldn't need a macro system
We haven't implemented it? I thought it already worked
Just isn't implemented for the JSON decoder
I don't think we have it for Decoding
but I could be misremembering :big_smile:
Oh... intriguing. I don't recall at this point. That said, we still plan to revamp the whole system.
But yeah, no macro system needed.
You have autoderive or a manual implementation. Either is fine.
It's also missing from the Ability definition
Ok
Last I checked with the work to revamp decode, it was stuck on lambdaset bugs.
But we should be able to add tag decoding directly to the old decode
The compiler panics with
thread '<unnamed>' panicked at crates/compiler/mono/src/ir.rs:6257:10:
Ability specialization is unknown. Tip: check out <https://roc.zulipchat.com/#na
rrow/stream/231634-beginners/topic/Non-Functions.20in.20Abilities/near/456068617
>: DeriveError(Underivable)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I was trying out roc and decided to implement lamdera in roc by writing a platform but I've gotten stuck on sending messages over the wire.
This is with a tag?
Yes that is what happens with a tag
There's a different but similar message for Opaque types too
If so, we need to add tag decoding to the ability. Then we need to add autoderive for it in the compiler.
Would be very similar to the autoderrive for encoding a tag
Trying to decode with an opaque type errors with
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
expected to know a specialization for `17.IdentId(2)`#`13.IdentId(4)`, but it wasn't found
Location: crates/compiler/solve/src/specialize.rs:749:29
But my assumption is that this is intentional
Brendan Hansknecht said:
Would be very similar to the autoderrive for encoding a tag
Should I create an issue for it? You mentioned that there is work to revamp the code
I will take a look at the compiler and try to implement an autoderive.
What is reasonable API for a tag method in the DeocderFormatting
ability?
With the current decode it should be very similar to a tuple. It should just decode a string tag name before decoding the tuple fields
I assume something similar to record and tuple like
tuple : state, (state, Str -> [Select (Decoder state fmt), Next]), (state -> Result val DecodeError) -> Decoder val fmt where fmt implements DecoderFormatting
but the nested decoding requirements where each variant would then need to decode a variable number of fields does feel like it may require more information like the index of the current tuple field
The alternative would just be push all of that to the state
Last updated: Jul 06 2025 at 12:14 UTC