improve non-const array size error
authorJudah Caruso <judah@tuta.io>
Thu, 7 Dec 2023 19:03:52 +0000 (12:03 -0700)
committerJudah Caruso <judah@tuta.io>
Thu, 7 Dec 2023 19:03:52 +0000 (12:03 -0700)
compiler/src/types.c

index 7aceffb45546cf38621c335879ca653c43864f0a..ee17680ab1a53b0cfcf54115a4f53b7705c9e8c3 100644 (file)
@@ -382,8 +382,14 @@ static Type* type_build_from_ast_inner(bh_allocator alloc, AstType* type_node, b
                 count = get_expression_integer_value(a_node->count_expr, &valid);
 
                 if (!valid) {
-                    onyx_report_error(a_node->token->pos, Error_Critical, "Array type size expression must be 'i32', got '%s'.",
-                        type_get_name(a_node->count_expr->type));
+                    if (!(a_node->count_expr->flags & Ast_Flag_Const)) {
+                        onyx_report_error(a_node->token->pos, Error_Critical, "Array type size must be a constant expression.");
+                    }
+                    else {
+                        onyx_report_error(a_node->token->pos, Error_Critical, "Array type size expression must be 'i32', got '%s'.",
+                            type_get_name(a_node->count_expr->type));
+                    }
+
                     return NULL;
                 }