diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-17 10:36:49 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-17 10:36:49 +0100 |
| commit | 1bc0e66ed15bba0cdc1b27fec8a1f06a4c9144be (patch) | |
| tree | 52c78cadd4d32cbf526d9cce8f1d28c7acc66fd9 /src/check_builtin.cpp | |
| parent | 117d32dfc476bffdcc526003538710794874018d (diff) | |
Improve error message for using `offset_of` within a struct itself of that struct
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index f0db6afc4..48cf73b58 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1899,6 +1899,21 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 gb_string_free(t); return false; } + + Type *bt = base_type(type); + if (bt->kind == Type_Struct && bt->Struct.scope != nullptr) { + if (is_type_polymorphic(bt)) { + gbString t = type_to_string(type); + error(field_arg, "Cannot use '%.*s' on an unspecialized polymorphic struct type, got '%s'", LIT(builtin_name), t); + gb_string_free(t); + return false; + } else if (bt->Struct.fields.count == 0 && bt->Struct.node == nullptr) { + gbString t = type_to_string(type); + error(field_arg, "Cannot use '%.*s' on incomplete struct declaration, got '%s'", LIT(builtin_name), t); + gb_string_free(t); + return false; + } + } Selection sel = lookup_field(type, field_name, false); if (sel.entity == nullptr) { |