diff --git a/releasenotes.md b/releasenotes.md index 1a774a127..afc1f9d44 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -27,6 +27,7 @@ - Variable aliases could not be assigned to. - Some folding was missing in binary op compile time resolution #2135. - Defining an enum like `ABC = { 1 2 }` was accidentally allowed. +- Using a non-const as the end range for a bitstruct would trigger an assert. ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 81560d008..ee733ba1c 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -825,7 +825,7 @@ static inline bool sema_analyse_bitstruct_member(SemaContext *context, Decl *par if (end) { // Analyse the end - if (!sema_analyse_expr(context, start)) return false; + if (!sema_analyse_expr(context, end)) return false; if (!sema_cast_const(end) || !type_is_integer(end->type) || int_is_neg(end->const_expr.ixx)) { SEMA_ERROR(end, "This must be a constant non-negative integer value."); diff --git a/test/test_suite/bitstruct/bitstruct_end_func.c3t b/test/test_suite/bitstruct/bitstruct_end_func.c3t new file mode 100644 index 000000000..29cb6a015 --- /dev/null +++ b/test/test_suite/bitstruct/bitstruct_end_func.c3t @@ -0,0 +1,15 @@ +module test; +import std::io; + +macro foo() => 3; +macro bar() => 4; +bitstruct Foo : int +{ + int a : 1..2; + int b : foo()..(bar()) @tag("foo", "a"); +} + +fn void main() +{ + +}