pub enum FieldNarrowingTest {
NonNull,
Shape(Type),
Interface(InterfaceNarrowingTest),
Substituted,
Representation,
}Expand description
What a redeclared field’s read guard verifies before it casts. The typechecker selects the most precise test codegen can lower, falling back to a read-time substituted test for erased class parameters.
Variants§
NonNull
The two declarations differ only in admitting null, so presence is the
whole check. Worth its own case: the structural walk below is O(size of
the stored value), and this is both the commonest narrowing and the one
where walking proves nothing. It also has no shape to lower, so it guards
types Shape cannot — a recursive one, an interface with methods.
Whether the test actually runs is settled at the read, not here: an
erased type parameter’s v: T is string | null at Sub<string | null>,
where a null is legal, and string at Sub<string>, where it is not.
emit_narrowed_field_read asks the substituted read type and skips the
test when it admits null.
Shape(Type)
Structural conformance to this shape, which is restricted to what
cast_check::emit_structural_test can lower.
Interface(InterfaceNarrowingTest)
Runtime member check for an interface. Methods are read through the object-shape getter (which can surface class vtable slots), while data properties use the ordinary accessor-aware conformance walk. The method set is empty for a data-only interface.
Substituted
The declaration contains an erased class type parameter, so its concrete
runtime shape is available only at the read. Codegen tests the
substituted result_ty rather than silently falling back to a bare cast.
Representation
Only the target Wasm representation can be established. This still
makes the following cast safe and turns mismatches into TypeError.