diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 51e8885cdf..abb1c9f765 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -41,9 +41,9 @@ #include "src/ast/type/struct_type.h" #include "src/ast/type/vector_type.h" #include "src/ast/type_constructor_expression.h" -#include "src/ast/unary_op_expression.h" #include "src/ast/unary_derivative_expression.h" #include "src/ast/unary_method_expression.h" +#include "src/ast/unary_op_expression.h" #include "src/ast/unless_statement.h" #include "src/ast/variable_decl_statement.h" @@ -381,9 +381,8 @@ bool TypeDeterminer::DetermineRelational(ast::RelationalExpression* expr) { } else if (lhs_type->IsMatrix() && rhs_type->IsVector()) { auto mat = lhs_type->AsMatrix(); - expr->set_result_type( - ctx_.type_mgr().Get(std::make_unique( - mat->type(), mat->rows()))); + expr->set_result_type(ctx_.type_mgr().Get( + std::make_unique(mat->type(), mat->rows()))); } else if (lhs_type->IsVector() && rhs_type->IsMatrix()) { auto mat = rhs_type->AsMatrix(); expr->set_result_type( @@ -487,12 +486,12 @@ bool TypeDeterminer::DetermineUnaryMethod(ast::UnaryMethodExpression* expr) { } bool TypeDeterminer::DetermineUnaryOp(ast::UnaryOpExpression* expr) { - // Result type matches the parameter type. - if (!DetermineResultType(expr->expr())) { - return false; - } - expr->set_result_type(expr->expr()->result_type()); - return true; + // Result type matches the parameter type. + if (!DetermineResultType(expr->expr())) { + return false; + } + expr->set_result_type(expr->expr()->result_type()); + return true; } } // namespace tint diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index 5e9179d960..82754066c4 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -41,7 +41,6 @@ #include "src/ast/struct.h" #include "src/ast/struct_member.h" #include "src/ast/switch_statement.h" -#include "src/ast/unary_op_expression.h" #include "src/ast/type/array_type.h" #include "src/ast/type/bool_type.h" #include "src/ast/type/f32_type.h" @@ -52,6 +51,7 @@ #include "src/ast/type_constructor_expression.h" #include "src/ast/unary_derivative_expression.h" #include "src/ast/unary_method_expression.h" +#include "src/ast/unary_op_expression.h" #include "src/ast/unless_statement.h" #include "src/ast/variable_decl_statement.h" @@ -105,6 +105,12 @@ TEST_F(TypeDeterminerTest, Stmt_Break) { EXPECT_TRUE(cond_ptr->result_type()->IsI32()); } +TEST_F(TypeDeterminerTest, Stmt_Break_WithoutCondition) { + ast::type::I32Type i32; + ast::BreakStatement brk; + EXPECT_TRUE(td()->DetermineResultType(&brk)); +} + TEST_F(TypeDeterminerTest, Stmt_Case) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -145,6 +151,12 @@ TEST_F(TypeDeterminerTest, Stmt_Continue) { EXPECT_TRUE(cond_ptr->result_type()->IsI32()); } +TEST_F(TypeDeterminerTest, Stmt_Continue_WithoutStatement) { + ast::type::I32Type i32; + ast::ContinueStatement stmt; + EXPECT_TRUE(td()->DetermineResultType(&stmt)); +} + TEST_F(TypeDeterminerTest, Stmt_Else) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -313,6 +325,12 @@ TEST_F(TypeDeterminerTest, Stmt_Return) { EXPECT_TRUE(cond_ptr->result_type()->IsI32()); } +TEST_F(TypeDeterminerTest, Stmt_Return_WithoutValue) { + ast::type::I32Type i32; + ast::ReturnStatement ret; + EXPECT_TRUE(td()->DetermineResultType(&ret)); +} + TEST_F(TypeDeterminerTest, Stmt_Switch) { ast::type::I32Type i32; ast::type::F32Type f32;