Skip to main content

lower_field_default_wire

Function lower_field_default_wire 

Source
pub fn lower_field_default_wire(
    init: &Expr,
    expected: &TypeRef,
    types: &HashMap<String, Arc<TypeDecl>>,
) -> Result<(), DefaultReason>
Expand description

Events slice 3a (#972): whether an event field’s default is closed-form, so that the JSON it deserialises from when its key is absent from the incoming JSON can be built. Type-directed — given the field’s expected TypeRef and the visible types table, every syntactic ambiguity (a bare Ident that is really a sum variant, a FieldAccess that is a qualified nullary variant) resolves the same way the checker resolves it, just narrower (a bare name must match a variant of this expected sum specifically) — so this needs no per-expression Ty map (expr_types), which a subscriber regenerating a publisher’s own event codec (emit_consumed_context_helpers) has no way to obtain anyway.

It is the checker’s validation and nothing else (1A.40b, #3996): Err(reason) for anything not closed-form, which bynk.types.bad_field_default reports at check time, and Ok(()) otherwise. The wire form of a default the emitter splices into a codec is a pure function of field_default_value’s tree (wire_default_node in bynk-emit), so this crate writes no TypeScript text for it. The two walks share sum_default_parts, record_default_field, inst_record_fields and base_value; a test pins that they agree on every case.