aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-06-06 23:55:48 +0100
committergingerBill <bill@gingerbill.org>2024-06-06 23:55:48 +0100
commit7044a7d77650e922a66f3bfe99711f3ed370e1ba (patch)
treec31f6413c08b69f6598dbe406c6cb1e5efec2642 /src/check_builtin.cpp
parent08612423b9afffb7499d8db2c69715df1627bd50 (diff)
Try to fix a possible race condition with polymorphic record parameters
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 7e3bcb7ee..eef925d94 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -5912,15 +5912,9 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
if (operand->mode != Addressing_Type) {
error(operand->expr, "Expected a record type for '%.*s'", LIT(builtin_name));
} else {
- Type *bt = base_type(operand->type);
- if (bt->kind == Type_Struct) {
- if (bt->Struct.polymorphic_params != nullptr) {
- operand->value = exact_value_i64(bt->Struct.polymorphic_params->Tuple.variables.count);
- }
- } else if (bt->kind == Type_Union) {
- if (bt->Union.polymorphic_params != nullptr) {
- operand->value = exact_value_i64(bt->Union.polymorphic_params->Tuple.variables.count);
- }
+ TypeTuple *tuple = get_record_polymorphic_params(operand->type);
+ if (tuple) {
+ operand->value = exact_value_i64(tuple->variables.count);
} else {
error(operand->expr, "Expected a record type for '%.*s'", LIT(builtin_name));
}
@@ -5952,20 +5946,11 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
Entity *param = nullptr;
i64 count = 0;
- Type *bt = base_type(operand->type);
- if (bt->kind == Type_Struct) {
- if (bt->Struct.polymorphic_params != nullptr) {
- count = bt->Struct.polymorphic_params->Tuple.variables.count;
- if (index < count) {
- param = bt->Struct.polymorphic_params->Tuple.variables[cast(isize)index];
- }
- }
- } else if (bt->kind == Type_Union) {
- if (bt->Union.polymorphic_params != nullptr) {
- count = bt->Union.polymorphic_params->Tuple.variables.count;
- if (index < count) {
- param = bt->Union.polymorphic_params->Tuple.variables[cast(isize)index];
- }
+ TypeTuple *tuple = get_record_polymorphic_params(operand->type);
+ if (tuple) {
+ count = tuple->variables.count;
+ if (index < count) {
+ param = tuple->variables[cast(isize)index];
}
} else {
error(operand->expr, "Expected a specialized polymorphic record type for '%.*s'", LIT(builtin_name));