mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 13:38:00 +00:00
[type-determiner] return false when type determining an undeclared function
Change-Id: Ia7e43be64675528037f92026a6c239d1e5220fc0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26941 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
8fcf269d4b
commit
844f632785
@@ -511,6 +511,15 @@ bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!expr->func()->result_type()) {
|
||||
auto func_name = expr->func()->AsIdentifier()->name();
|
||||
set_error(
|
||||
expr->source(),
|
||||
"v-0005: function must be declared before use: '" + func_name + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
expr->set_result_type(expr->func()->result_type());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -387,6 +387,34 @@ TEST_F(TypeDeterminerTest, Stmt_Call) {
|
||||
EXPECT_TRUE(expr_ptr->result_type()->IsF32());
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
|
||||
// fn main() -> void {func(); return; }
|
||||
// fn func() -> void { return; }
|
||||
ast::type::F32Type f32;
|
||||
ast::ExpressionList call_params;
|
||||
auto call_expr = std::make_unique<ast::CallExpression>(
|
||||
Source{12, 34}, std::make_unique<ast::IdentifierExpression>("func"),
|
||||
std::move(call_params));
|
||||
ast::VariableList params0;
|
||||
auto func_main =
|
||||
std::make_unique<ast::Function>("main", std::move(params0), &f32);
|
||||
auto main_body = std::make_unique<ast::BlockStatement>();
|
||||
main_body->append(std::make_unique<ast::CallStatement>(std::move(call_expr)));
|
||||
main_body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func_main->set_body(std::move(main_body));
|
||||
mod()->AddFunction(std::move(func_main));
|
||||
|
||||
auto func = std::make_unique<ast::Function>("func", std::move(params0), &f32);
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
mod()->AddFunction(std::move(func));
|
||||
|
||||
EXPECT_FALSE(td()->Determine()) << td()->error();
|
||||
EXPECT_EQ(td()->error(),
|
||||
"12:34: v-0005: function must be declared before use: 'func'");
|
||||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Stmt_VariableDecl) {
|
||||
ast::type::I32Type i32;
|
||||
auto var =
|
||||
|
||||
Reference in New Issue
Block a user