Skip to content

Commit

Permalink
Check type of comma operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Lai-YT authored and leewei05 committed Jun 13, 2024
1 parent dfc494a commit 6e79126
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/type_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ void TypeChecker::Visit(UnaryExprNode& unary_expr) {
void TypeChecker::Visit(BinaryExprNode& bin_expr) {
bin_expr.lhs->Accept(*this);
bin_expr.rhs->Accept(*this);

// NOTE: The left operand of a comma operator is evaluated as a void
// expression; there is a sequence point after its evaluation. Then the right
// operand is evaluated; the result has its type and value.
if (bin_expr.op == BinaryOperator::kComma) {
bin_expr.type = bin_expr.rhs->type->Clone();
return;
}

if (!bin_expr.lhs->type->IsEqual(*bin_expr.rhs->type)) {
// TODO: invalid operands to binary +
} else {
Expand Down

0 comments on commit 6e79126

Please sign in to comment.