aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-06-01 14:33:38 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-06-01 14:35:53 -0400
commitb70d2b156ad05d1c33a34ca9b1fedb6b2f888328 (patch)
treee9609e43c2e671ab4503890d85aff3794ccdc70f /src/check_builtin.cpp
parent705ae3f34380f33d1a7e391400ef692becd38c14 (diff)
Make `quaternion` untyped values convert to first typed value found
This fixes an issue (#2079) where a typed argument could cause the construction to fail on the basis of failed untyped -> typed conversion.
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index fe3106162..7e043323a 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -2871,8 +2871,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
// quaternion :: proc(imag, jmag, kmag, real: float_type) -> complex_type
Operand xyzw[4] = {};
- u32 first_index = 0;
-
// NOTE(bill): Invalid will be the default till fixed
operand->type = t_invalid;
operand->mode = Addressing_Invalid;
@@ -2934,7 +2932,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
if (!ok || index < 0) {
return false;
}
- first_index = cast(u32)index;
*refs[index] = o;
}
@@ -2959,12 +2956,17 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
}
- for (u32 i = 0; i < 4; i++ ){
- u32 j = (i + first_index) % 4;
- if (j == first_index) {
- convert_to_typed(c, &xyzw[j], xyzw[(first_index+1)%4].type); if (xyzw[j].mode == Addressing_Invalid) return false;
- } else {
- convert_to_typed(c, &xyzw[j], xyzw[first_index].type); if (xyzw[j].mode == Addressing_Invalid) return false;
+ // The first typed value found, if any exist, will dictate the type for all untyped values.
+ for (u32 i = 0; i < 4; i++) {
+ if (is_type_typed(xyzw[i].type)) {
+ for (u32 j = 0; j < 4; j++) {
+ // `convert_to_typed` should check if it is typed already.
+ convert_to_typed(c, &xyzw[j], xyzw[i].type);
+ if (xyzw[j].mode == Addressing_Invalid) {
+ return false;
+ }
+ }
+ break;
}
}
if (xyzw[0].mode == Addressing_Constant &&
@@ -3024,7 +3026,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
operand->mode = Addressing_Constant;
}
- BasicKind kind = core_type(xyzw[first_index].type)->Basic.kind;
+ BasicKind kind = core_type(xyzw[0].type)->Basic.kind;
switch (kind) {
case Basic_f16: operand->type = t_quaternion64; break;
case Basic_f32: operand->type = t_quaternion128; break;