Use context.assertion_failure_proc with type assertions when the context is available, otherwise use a trivial trap.

This commit is contained in:
gingerBill
2026-01-26 18:23:29 +00:00
parent 467954bc7b
commit 3586bda6ae
5 changed files with 509 additions and 37 deletions

View File

@@ -3865,7 +3865,12 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
args[4] = lb_typeid(p->module, src_type);
args[5] = lb_typeid(p->module, dst_type);
}
lb_emit_runtime_call(p, "type_assertion_check", args);
char const *name = "type_assertion_check_contextless";
if (p->context_stack.count > 0) {
name = "type_assertion_check_with_context";
}
lb_emit_runtime_call(p, name, args);
}
lbValue data_ptr = v;
@@ -3881,16 +3886,28 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
lbValue any_id = lb_emit_struct_ev(p, v, 1);
isize arg_count = 6;
if (build_context.no_rtti) {
arg_count = 4;
}
lbValue id = lb_typeid(p->module, type);
lbValue ok = lb_emit_comp(p, Token_CmpEq, any_id, id);
auto args = array_make<lbValue>(permanent_allocator(), 6);
auto args = array_make<lbValue>(permanent_allocator(), arg_count);
args[0] = ok;
lb_set_file_line_col(p, array_slice(args, 1, args.count), pos);
args[4] = any_id;
args[5] = id;
lb_emit_runtime_call(p, "type_assertion_check", args);
if (!build_context.no_rtti) {
args[4] = any_id;
args[5] = id;
}
char const *name = "type_assertion_check_contextless";
if (p->context_stack.count > 0) {
name = "type_assertion_check_with_context";
}
lb_emit_runtime_call(p, name, args);
}
return lb_emit_conv(p, data_ptr, tv.type);