pub struct FieldNarrowingCheck {
pub declaration: Option<MangledName>,
pub test: FieldNarrowingTest,
pub minimal_test_target: Option<Type>,
pub message: String,
}Expand description
A read guard for a field whose subclass declaration narrows the inherited one. The two declarations share one storage slot, so a write that goes through the parent’s — an inherited method, a parent-typed reference, the parent’s constructor — can leave the slot holding a value the subclass’s declaration does not admit. The language accepts the narrowing anyway (spec.md §Classes, matching TypeScript), so the read is what has to check.
Without this the read’s bare ref.cast raises an uncatchable cast failure
naming nothing the author wrote; with it, the read runs test first —
presence for a narrowing that only strips null, structural conformance
otherwise — and throws message as a catchable TypeError.
Fields§
§declaration: Option<MangledName>§test: FieldNarrowingTest§minimal_test_target: Option<Type>A concrete declaration type whose ancestor alternatives need only a presence or representation check. Other read types still validate fully.
message: String