Skip to main content

check_event_field_default

Function check_event_field_default 

Source
pub fn check_event_field_default(
    init: &Expr,
    field_type: &TypeRef,
    input: &ResolvedCommons,
    tys: &Types,
    expr_types: &mut HashMap<ExprId, TypedExpr>,
    callees: &mut HashMap<ExprId, Callee>,
    errors: &mut Vec<CompileError>,
    refs: &mut RefSink,
    hints: &mut HintSink,
    locals: &mut LocalsSink,
)
Expand description

Events slice 3a (#972): type-check an event field’s default expression (field: T = init), reusing check_static_initialiser’s empty-pure-scope discipline. Pushes bynk.event.bad_field_default.

One admission check_static_initialiser doesn’t cover on its own: an opaque type’s T.unsafe(lit) is, by design (ADR 0182), a bypass of its own refinement — type_of’s ordinary ConstructorCall handling only checks lit’s base type, not the refinement, since that’s the whole point of unsafe. An event field default is different: it becomes part of the wire codec (slice 3a lowers it to its wire JSON form and splices it into deserialise_<Event>, which validates a defaulted value exactly like a real one), so a default that bypasses its own refinement would compile cleanly and then fail at runtime the first time an old event actually triggers it — a deferred, surprising failure this check closes statically instead. Only T.unsafe(lit) on a literal argument is checked here (anything else already fails the static-value requirement above); a violated refinement pushes the same bynk.event.bad_field_default.