diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 86e35570b4..9048b2f3ee 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -21,6 +21,7 @@ #include "src/ast/else_statement.h" #include "src/ast/if_statement.h" #include "src/ast/loop_statement.h" +#include "src/ast/regardless_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type_constructor_expression.h" @@ -123,6 +124,11 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { return DetermineResultType(l->body()) && DetermineResultType(l->continuing()); } + if (stmt->IsRegardless()) { + auto r = stmt->AsRegardless(); + return DetermineResultType(r->condition()) && + DetermineResultType(r->body()); + } if (stmt->IsNop()) { return true; } diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 75fb75ac34..6c591b4161 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -27,6 +27,7 @@ #include "src/ast/if_statement.h" #include "src/ast/int_literal.h" #include "src/ast/loop_statement.h" +#include "src/ast/regardless_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" @@ -247,6 +248,36 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) { EXPECT_TRUE(continuing_rhs_ptr->result_type()->IsF32()); } +TEST_F(TypeDeterminerTest, Stmt_Regardless) { + ast::type::I32Type i32; + ast::type::F32Type f32; + + auto lhs = std::make_unique( + std::make_unique(&i32, 2)); + auto lhs_ptr = lhs.get(); + + auto rhs = std::make_unique( + std::make_unique(&f32, 2.3f)); + auto rhs_ptr = rhs.get(); + + ast::StatementList body; + body.push_back(std::make_unique(std::move(lhs), + std::move(rhs))); + + ast::RegardlessStatement regardless( + std::make_unique( + std::make_unique(&i32, 3)), + std::move(body)); + + EXPECT_TRUE(td()->DetermineResultType(®ardless)); + ASSERT_NE(regardless.condition()->result_type(), nullptr); + ASSERT_NE(lhs_ptr->result_type(), nullptr); + ASSERT_NE(rhs_ptr->result_type(), nullptr); + EXPECT_TRUE(regardless.condition()->result_type()->IsI32()); + EXPECT_TRUE(lhs_ptr->result_type()->IsI32()); + EXPECT_TRUE(rhs_ptr->result_type()->IsF32()); +} + TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) { ast::type::F32Type f32; ast::ScalarConstructorExpression s(