aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-01-26 18:23:29 +0000
committergingerBill <gingerBill@users.noreply.github.com>2026-01-26 18:23:29 +0000
commit3586bda6ae80b1dca1984ae54b023d5fec69067e (patch)
treed1b8bba874b42fae91e12f095f10ad017bef9b34 /src/check_expr.cpp
parent467954bc7baed8061348b6dc5ddda1a742ea69f4 (diff)
Use `context.assertion_failure_proc` with type assertions when the `context` is available, otherwise use a trivial trap.
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 42a398597..7d2240fdf 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -11064,8 +11064,20 @@ gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *no
end:;
if ((c->state_flags & StateFlag_no_type_assert) == 0) {
- add_package_dependency(c, "runtime", "type_assertion_check");
- add_package_dependency(c, "runtime", "type_assertion_check2");
+ bool has_context = true;
+ if (c->proc_name.len == 0 && c->curr_proc_sig == nullptr) {
+ has_context = false;
+ } else if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
+ has_context = false;
+ }
+
+ if (has_context) {
+ add_package_dependency(c, "runtime", "type_assertion_check_with_context");
+ add_package_dependency(c, "runtime", "type_assertion_check2_with_context");
+ } else {
+ add_package_dependency(c, "runtime", "type_assertion_check_contextless");
+ add_package_dependency(c, "runtime", "type_assertion_check2_contextless");
+ }
}
return kind;
}