diff --git a/releasenotes.md b/releasenotes.md index 8a30c37b1..07aba97db 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 1e95fc25a..5c5667384 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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."); diff --git a/test/unit/regression/vector_ops.c3 b/test/unit/regression/vector_ops.c3 index 38c1cd567..4e0b6f979 100644 --- a/test/unit/regression/vector_ops.c3 +++ b/test/unit/regression/vector_ops.c3 @@ -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 };