pub fn target_allows_null(
ctx: &CodegenCtx<'_>,
ty: &Type,
) -> Result<bool, CompilerFailure>Expand description
Whether emit_cast_to lets a null reach the target rather than lifting to
non-null first. True for the targets whose lowering is a nullable
(ref null $Object): bare Null, nullable unions, and the no-op
erased/dynamic types — unknown, never, an erased generic (which can hold
null after instantiation, e.g. T = string | null), and a recursion back-edge
whose body may list null. emit_cast_to’s Union arm uses RefCastNullable
for the same reason. A union’s nullability is its lowering, not whether a
member is spelled null: T | number lowers nullable because T does.
A caller that must not hand emit_cast_to a null has to ask this, not
is_nullable_ref: the two disagree — an InterfaceRef lowers to a nullable
slot and is still ref.as_non_nulled there, which traps.