From 6e79126a7df44075b22d382e44540d78e4cb1909 Mon Sep 17 00:00:00 2001 From: Lai-YT <381xvmvbib@gmail.com> Date: Mon, 10 Jun 2024 16:12:01 +0800 Subject: [PATCH] Check type of comma operator --- src/type_checker.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/type_checker.cpp b/src/type_checker.cpp index 04c40d5e..a2e9a282 100644 --- a/src/type_checker.cpp +++ b/src/type_checker.cpp @@ -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 {