Add missing break, continue and return tests.
This CL adds tests for break, continue and return without attached
expressions.
Bug: tint:5
Change-Id: I8c4221e787af95f5597db3ea4e42b38962223bf4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18980
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 51e8885..abb1c9f 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 @@
} else if (lhs_type->IsMatrix() && rhs_type->IsVector()) {
auto mat = lhs_type->AsMatrix();
- expr->set_result_type(
- ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
- mat->type(), mat->rows())));
+ expr->set_result_type(ctx_.type_mgr().Get(
+ std::make_unique<ast::type::VectorType>(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::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 5e9179d..8275406 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 @@
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 @@
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 @@
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;