From 2094cd4768e4b6c19e4dfb674cecf89505ef3d3d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 19 May 2026 15:27:34 +0100 Subject: [PATCH] Add suggestion for ternary if with simd --- src/check_builtin.cpp | 8 ++++---- src/check_expr.cpp | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 4cbdbefa6..0a7943a4d 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1403,9 +1403,9 @@ gb_internal bool check_builtin_simd_operation(CheckerContext *c, Operand *operan return false; } Type *elem = base_array_type(x.type); - if (!is_type_boolean(elem)) { + if (!is_type_boolean(elem) && !is_type_integer(elem)) { gbString xs = type_to_string(x.type); - error(x.expr, "'%.*s' expected a #simd type with a boolean element, got '%s'", LIT(builtin_name), xs); + error(x.expr, "'%.*s' expected a #simd type with a boolean or an integer element, got '%s'", LIT(builtin_name), xs); gb_string_free(xs); return false; } @@ -1572,8 +1572,8 @@ gb_internal bool check_builtin_simd_operation(CheckerContext *c, Operand *operan Operand x = {}; Operand y = {}; - check_expr(c, &x, ce->args[1]); if (x.mode == Addressing_Invalid) return false; - check_expr_with_type_hint(c, &y, ce->args[2], x.type); if (y.mode == Addressing_Invalid) return false; + check_expr_with_type_hint(c, &x, ce->args[1], type_hint); if (x.mode == Addressing_Invalid) return false; + check_expr_with_type_hint(c, &y, ce->args[2], x.type); if (y.mode == Addressing_Invalid) return false; convert_to_typed(c, &y, x.type); if (y.mode == Addressing_Invalid) return false; if (!is_type_simd_vector(x.type)) { error(x.expr, "'%.*s' expected a simd vector type", LIT(builtin_name)); diff --git a/src/check_expr.cpp b/src/check_expr.cpp index bb7a181df..ed2115a30 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -9681,7 +9681,11 @@ gb_internal ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *n node->viral_state_flags |= te->cond->viral_state_flags; if (cond.mode != Addressing_Invalid && !is_type_boolean(cond.type)) { + ERROR_BLOCK(); error(te->cond, "Non-boolean condition in ternary if expression"); + if (is_type_simd_vector(cond.type)) { + error_line("\tSuggestion: Use 'simd.select' a ternary-like operation is required\n"); + } } Operand x = {Addressing_Invalid};