% analysis was incorrect for int vectors.

This commit is contained in:
Christoffer Lerno
2024-08-09 15:23:40 +02:00
parent 44db4a21fc
commit f3e5268083
3 changed files with 12 additions and 2 deletions

View File

@@ -52,6 +52,7 @@
- Better error when casting to a distinct fails.
- With single module, name the .o file after what `-o` provides. #1306
- Bitstruct members can now have attributes.
- `%` analysis was incorrect for int vectors.
### Stdlib changes

View File

@@ -6010,9 +6010,8 @@ static bool sema_expr_analyse_mod(SemaContext *context, Expr *expr, Expr *left,
expr->const_expr.fxx = float_rem(left->const_expr.fxx, right->const_expr.fxx);
}
}
else
else if (type_is_integer(flat))
{
assert(type_is_integer(flat));
// 3. a % 0 is not valid, so detect it.
if (sema_cast_const(right) && int_is_zero(right->const_expr.ixx)) RETURN_SEMA_ERROR(right, "Cannot perform %% with a constant zero.");

View File

@@ -1,5 +1,15 @@
import std::io;
fn void! test_int_mod() @test
{
int[<2>] y = { 10, 99 };
int[<2>] z = { 3, 5 };
assert(y % z == { 1, 4 });
assert(y / z == { 3, 19 });
assert(int[<2>]{ 10, 99 } % int[<2>]{ 3, 5 } == { 1, 4 });
assert(int[<2>]{ 10, 99 } / int[<2>]{ 3, 5 } == { 3, 19 });
}
fn void! test_conv() @test
{
float[<4>] y = { 1, 2, 3, 4 };