diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-31 19:06:17 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2024-08-31 19:06:17 +0200 |
| commit | a4ac50a5b455a4ebc21806d4b9e0529b8a4b796c (patch) | |
| tree | 23ccfbef938629e23a672428bae8547519416f8c | |
| parent | 6ba1506aa93d86d19c4e572ec060cde0b1855268 (diff) | |
Check for `#assert` condition to be a constant bool
Fixes #4170
| -rw-r--r-- | src/check_builtin.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 3742caeda..d2ad304bc 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1792,7 +1792,17 @@ gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *o error(call, "'#assert' expects either 1 or 2 arguments, got %td", ce->args.count); return false; } - if (!is_type_boolean(operand->type) || operand->mode != Addressing_Constant) { + + // operand->type can be nil if the condition is a procedure, for example: #assert(assert()) + // So let's check it before we use it, so we get the same error as if we wrote `#exists(assert()) + Ast *arg = ce->args[0]; + Entity *e = nullptr; + Operand o = {}; + if (arg->kind == Ast_Ident) { + e = check_ident(c, &o, arg, nullptr, nullptr, true); + } + + if (operand->type == nullptr || !is_type_boolean(operand->type) || operand->mode != Addressing_Constant) { gbString str = expr_to_string(ce->args[0]); error(call, "'%s' is not a constant boolean", str); gb_string_free(str); |