Stream: compiler development

Topic: ✔ opaque type Encoding/Decoding derivation


view this post on Zulip Dzmitry Misiuk (Jul 26 2026 at 19:56):

Does the new compiler derive Encoding/Decoding for opaque types yet, or is that not in? Username := Str gives MISSING METHOD … encoder_for (records/lists/tuples/tag unions all derive fine). The old Rust compiler did it for opaques aliasing a builtin, and the docs still describe it — so I wasn't sure if it's a known gap or a deliberate change.

Context: I'm deriving OpenAPI straight from Roc types, and this is the one thing keeping a refined Username := Str from being a wire field (I re-validate at the boundary for now). Happy to file a minimal repro if useful.

view this post on Zulip Richard Feldman (Jul 26 2026 at 20:20):

you should be able to do encoder_for : _ and parser_for : _ in the opaque type declaration and that should give you auto-generated implementations for them

view this post on Zulip Richard Feldman (Jul 26 2026 at 20:20):

lmk if that doesn't work though!

view this post on Zulip Dzmitry Misiuk (Jul 26 2026 at 20:56):

That did it — thanks! I'd been writing a manual encoder_for body for a custom format and missing the plain encoder_for : _ / parser_for : _; the bare : _ auto-derives the JSON codec, and a record with the opaque field round-trips now. :folded_hands:

view this post on Zulip Notification Bot (Jul 26 2026 at 20:57):

Dzmitry Misiuk has marked this topic as resolved.

view this post on Zulip Notification Bot (Aug 03 2026 at 12:40):

Dzmitry Misiuk has marked this topic as resolved.


Last updated: Aug 12 2026 at 12:35 UTC