132. No custom destructuring; views are methods returning enums (2026-11-21)
- Decision. Patterns match only the stored shape of structs, enums
and tuples (with nesting, guards,
if let,let ... else). A library type cannot define its own pattern (Scalaunapply, F# active patterns). A view is a method returning an enum:match t.node(v): Leaf => ... Inner(l, r) => .... - Why. A custom pattern runs arbitrary code while looking like a free field read (costs stop being visible), defeats exhaustiveness checking, and needs a matcher protocol through the checker, LSP and trace, for a saving of one method call.
- Reverse. If 3 or more library families need the method-returning-
enum workaround and it hurts readability, add declared view enums that
lower to that method call, keeping exhaustiveness and
cpl explain. - Status. Accepted (closed by design).