mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix right -> left associativity for assignment.
This commit is contained in:
@@ -391,7 +391,15 @@ static Expr *parse_binary(Context *context, Expr *left_side)
|
||||
}
|
||||
else
|
||||
{
|
||||
right_side = TRY_EXPR_OR(parse_precedence(context, rules[operator_type].precedence + 1), poisoned_expr);
|
||||
// Assignment operators have precedence right -> left.
|
||||
if (rules[operator_type].precedence == PREC_ASSIGNMENT)
|
||||
{
|
||||
right_side = TRY_EXPR_OR(parse_precedence(context, PREC_ASSIGNMENT), poisoned_expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
right_side = TRY_EXPR_OR(parse_precedence(context, rules[operator_type].precedence + 1), poisoned_expr);
|
||||
}
|
||||
}
|
||||
|
||||
Expr *expr = EXPR_NEW_EXPR(EXPR_BINARY, left_side);
|
||||
|
||||
23
test/test_suite/expressions/assignment_precedence.c3t
Normal file
23
test/test_suite/expressions/assignment_precedence.c3t
Normal file
@@ -0,0 +1,23 @@
|
||||
module prec;
|
||||
|
||||
func void test()
|
||||
{
|
||||
int i = 1;
|
||||
int j = 2;
|
||||
int k = 3;
|
||||
int l = i = j = k;
|
||||
}
|
||||
|
||||
// #expect: prec.ll
|
||||
|
||||
%i = alloca i32, align 4
|
||||
%j = alloca i32, align 4
|
||||
%k = alloca i32, align 4
|
||||
%l = alloca i32, align 4
|
||||
store i32 1, i32* %i, align 4
|
||||
store i32 2, i32* %j, align 4
|
||||
store i32 3, i32* %k, align 4
|
||||
%0 = load i32, i32* %k, align 4
|
||||
store i32 %0, i32* %j, align 4
|
||||
store i32 %0, i32* %i, align 4
|
||||
store i32 %0, i32* %l, align 4
|
||||
Reference in New Issue
Block a user