diff options
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index ea89ec007..c0ba40503 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -778,12 +778,31 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 if (arg_count < max_count) { operand->type = alloc_type_array(elem_type, arg_count); } - operand->mode = Addressing_Value; + if (type->kind == Type_Array) { + if (operand->mode == Addressing_Variable) { + operand->mode = Addressing_SwizzleVariable; + } else { + operand->mode = Addressing_SwizzleValue; + } + } else { + operand->mode = Addressing_Value; + } - if (type_hint != nullptr && check_is_castable_to(c, operand, type_hint)) { - operand->type = type_hint; + Type *array_type = base_type(type_deref(operand->type)); + GB_ASSERT(array_type->kind == Type_Array); + + Type *swizzle_array_type = nullptr; + Type *bth = base_type(type_hint); + if (bth != nullptr && bth->kind == Type_Array && + bth->Array.count == arg_count && + are_types_identical(bth->Array.elem, array_type->Array.elem)) { + swizzle_array_type = type_hint; + } else { + swizzle_array_type = alloc_type_array(array_type->Array.elem, arg_count); } + operand->type = swizzle_array_type; + break; } |