diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-27 14:13:16 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-27 14:13:16 +0100 |
| commit | af83c30b6f5303dfddf8e38019c0431658b6e176 (patch) | |
| tree | 42972e4e2a94ea314792641a081799af6b9ad0ec /src/check_stmt.cpp | |
| parent | 27d9ab5dd8944878f53405e9d250c6ca788cc36a (diff) | |
And extra safety checks
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index f6e201011..5e7a8e323 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -2545,7 +2545,7 @@ gb_internal void check_if_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { // This needs to be improved tremendously, and a lot of it done during the // middle-end (or LLVM side) to improve checks and error messages void check_unsafe_return(Operand const &o, Type *type, Ast *expr) { - auto unsafe_return_error = [](Operand const &o, char const *msg, Type *extra_type=nullptr) { + auto const unsafe_return_error = [](Operand const &o, char const *msg, Type *extra_type=nullptr) { gbString s = expr_to_string(o.expr); if (extra_type) { gbString t = type_to_string(extra_type); @@ -2557,6 +2557,10 @@ void check_unsafe_return(Operand const &o, Type *type, Ast *expr) { gb_string_free(s); }; + if (type == nullptr || expr == nullptr) { + return; + } + if (expr->kind == Ast_CompoundLit && is_type_slice(type)) { ast_node(cl, CompoundLit, expr); if (cl->elems.count == 0) { @@ -2600,7 +2604,10 @@ void check_unsafe_return(Operand const &o, Type *type, Ast *expr) { for (Ast *elem : cl->elems) { if (elem->kind == Ast_FieldValue) { ast_node(fv, FieldValue, elem); - check_unsafe_return(o, entity_of_node(fv->field)->type, fv->value); + Entity *e = entity_of_node(fv->field); + if (e != nullptr) { + check_unsafe_return(o, e->type, fv->value); + } } } } |