diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2026-01-29 10:48:05 +0000 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2026-01-29 10:49:26 +0000 |
| commit | 07d814d9cf3bf2065e4122dba91817935dca7c60 (patch) | |
| tree | e19ee510f617a487d8e6391b59bfaf121efd8e36 /src/check_type.cpp | |
| parent | 4a7fb4666722b3ff45998c3bc11f03150a2fe53f (diff) | |
Add `struct #simple` to force a struct to use simple comparison if all of the fields "nearly simply comparable".
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 4b8f7b6ac..41c5f48d1 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -679,6 +679,21 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast * gb_unused(where_clause_ok); } check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context); + + if (st->is_simple) { + bool success = true; + for (Entity *f : struct_type->Struct.fields) { + if (!is_type_nearly_simple_compare(f->type)) { + gbString s = type_to_string(f->type); + error(f->token, "'struct #simple' requires all fields to be at least 'nearly simple compare', got %s", s); + gb_string_free(s); + } + } + if (success) { + struct_type->Struct.is_simple = true; + } + } + wait_signal_set(&struct_type->Struct.fields_wait_signal); } |