mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Second value in switch range not checked properly, causing an error on non-const values. #2777
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
- Create optional with `~` instead of `?`. `return io::EOF?;` becomes `return io::EOF~`.
|
||||
- Deprecated use of `?` to create optional.
|
||||
- Vectors not converted to arrays when passed as raw vaargs. #2776
|
||||
- Second value in switch range not checked properly, causing an error on non-const values. #2777
|
||||
|
||||
### Fixes
|
||||
- Regression with npot vector in struct triggering an assert #2219.
|
||||
|
||||
@@ -2432,10 +2432,10 @@ static inline bool sema_check_value_case(SemaContext *context, Type *switch_type
|
||||
*if_chained = true;
|
||||
return true;
|
||||
}
|
||||
if (is_range && !first_is_const)
|
||||
if (is_range)
|
||||
{
|
||||
sema_error_at(context, extend_span_with_token(expr->span, to_expr->span), "Ranges must be constant integers.");
|
||||
return false;
|
||||
bool second_is_const = sema_cast_const(to_expr) && (expr_is_const_int(to_expr) || expr_is_const_enum(to_expr));
|
||||
if (!first_is_const || !second_is_const) RETURN_SEMA_ERROR(first_is_const ? to_expr : expr, "Ranges must be constant integers or enum values, but this is not an integer / enum constant.");
|
||||
}
|
||||
bool is_enum = expr_is_const_enum(expr);
|
||||
ExprConst *const_expr = &expr->const_expr;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fn void main()
|
||||
{
|
||||
for (int i = 0; ; )
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 4 .. i: // #error: Ranges must be constant integers or enum values, but this is not an integer
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user