Program: Fix IsValid() state on TypeDeterminer error
The error was added to diagnostics_, and then this list was replaced with diagnostics from the builder. This resulted in the error silently being dropped. Change-Id: Ifdda99bfb1582fa5d0fa691f7d39cfe3f17e60e5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39901 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
42d1e097e6
commit
90da745fbd
|
@ -47,6 +47,7 @@ Program::Program(ProgramBuilder&& builder) {
|
||||||
TypeDeterminer td(&builder);
|
TypeDeterminer td(&builder);
|
||||||
if (!td.Determine()) {
|
if (!td.Determine()) {
|
||||||
diagnostics_.add_error(td.error());
|
diagnostics_.add_error(td.error());
|
||||||
|
is_valid_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ Program::Program(ProgramBuilder&& builder) {
|
||||||
builder.AST().GlobalVariables());
|
builder.AST().GlobalVariables());
|
||||||
sem_ = std::move(builder.Sem());
|
sem_ = std::move(builder.Sem());
|
||||||
symbols_ = std::move(builder.Symbols());
|
symbols_ = std::move(builder.Symbols());
|
||||||
diagnostics_ = std::move(builder.Diagnostics());
|
diagnostics_.add(std::move(builder.Diagnostics()));
|
||||||
builder.MarkAsMoved();
|
builder.MarkAsMoved();
|
||||||
|
|
||||||
if (!is_valid_ && !diagnostics_.contains_errors()) {
|
if (!is_valid_ && !diagnostics_.contains_errors()) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "src/ast/function.h"
|
#include "src/ast/function.h"
|
||||||
|
#include "src/ast/return_statement.h"
|
||||||
#include "src/ast/test_helper.h"
|
#include "src/ast/test_helper.h"
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/type/alias_type.h"
|
#include "src/type/alias_type.h"
|
||||||
|
@ -126,6 +127,18 @@ TEST_F(ProgramTest, IsValid_Invalid_Function) {
|
||||||
EXPECT_FALSE(program.IsValid());
|
EXPECT_FALSE(program.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ProgramTest, IsValid_Invalid_UnknownVar) {
|
||||||
|
Func("main", ast::VariableList{}, nullptr,
|
||||||
|
ast::StatementList{
|
||||||
|
create<ast::ReturnStatement>(Expr("unknown_ident")),
|
||||||
|
},
|
||||||
|
ast::FunctionDecorationList{});
|
||||||
|
|
||||||
|
Program program(std::move(*this));
|
||||||
|
EXPECT_FALSE(program.IsValid());
|
||||||
|
EXPECT_NE(program.Diagnostics().count(), 0u);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ProgramTest, IsValid_GeneratesError) {
|
TEST_F(ProgramTest, IsValid_GeneratesError) {
|
||||||
AST().AddGlobalVariable(nullptr);
|
AST().AddGlobalVariable(nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue