mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-10 04:18:11 +00:00
Unify semantics of the built-in swizzle procedure with the selector expression semantics e.g. .xyz
This commit is contained in:
@@ -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_hint != nullptr && check_is_castable_to(c, operand, type_hint)) {
|
||||
operand->type = type_hint;
|
||||
if (type->kind == Type_Array) {
|
||||
if (operand->mode == Addressing_Variable) {
|
||||
operand->mode = Addressing_SwizzleVariable;
|
||||
} else {
|
||||
operand->mode = Addressing_SwizzleValue;
|
||||
}
|
||||
} else {
|
||||
operand->mode = Addressing_Value;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user