mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-25 13:18:14 +00:00
Add suggestion for ternary if with simd
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user