resolver: Error on use of local decl in initalizer
`var x = x;` `let y = y;` Should not compile. Bug: tint:819 Bug: tint:1266 Change-Id: I6944a8a95d49329ef754aea3374f20b0dc91e513 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70660 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
93fc113837
commit
f83ada8b5d
|
@ -227,7 +227,6 @@ class DependencyScanner {
|
||||||
if (auto* l = stmt->As<ast::LoopStatement>()) {
|
if (auto* l = stmt->As<ast::LoopStatement>()) {
|
||||||
scope_stack_.Push();
|
scope_stack_.Push();
|
||||||
TINT_DEFER(scope_stack_.Pop());
|
TINT_DEFER(scope_stack_.Pop());
|
||||||
|
|
||||||
TraverseStatements(l->body->statements);
|
TraverseStatements(l->body->statements);
|
||||||
TraverseStatement(l->continuing);
|
TraverseStatement(l->continuing);
|
||||||
return;
|
return;
|
||||||
|
@ -256,9 +255,9 @@ class DependencyScanner {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto* v = stmt->As<ast::VariableDeclStatement>()) {
|
if (auto* v = stmt->As<ast::VariableDeclStatement>()) {
|
||||||
Declare(v->variable->symbol, v->variable);
|
|
||||||
TraverseType(v->variable->type);
|
TraverseType(v->variable->type);
|
||||||
TraverseExpression(v->variable->constructor);
|
TraverseExpression(v->variable->constructor);
|
||||||
|
Declare(v->variable->symbol, v->variable);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stmt->IsAnyOf<ast::BreakStatement, ast::ContinueStatement,
|
if (stmt->IsAnyOf<ast::BreakStatement, ast::ContinueStatement,
|
||||||
|
|
|
@ -782,6 +782,43 @@ INSTANTIATE_TEST_SUITE_P(Functions,
|
||||||
|
|
||||||
} // namespace undeclared_tests
|
} // namespace undeclared_tests
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Self reference by decl
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
namespace undeclared_tests {
|
||||||
|
|
||||||
|
using ResolverDependencyGraphDeclSelfUse = ResolverDependencyGraphTest;
|
||||||
|
|
||||||
|
TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalVar) {
|
||||||
|
const Symbol symbol = Sym("SYMBOL");
|
||||||
|
Global(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123));
|
||||||
|
Build(R"(error: cyclic dependency found: 'SYMBOL' -> 'SYMBOL'
|
||||||
|
12:34 note: var 'SYMBOL' references var 'SYMBOL' here)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverDependencyGraphDeclSelfUse, GlobalLet) {
|
||||||
|
const Symbol symbol = Sym("SYMBOL");
|
||||||
|
GlobalConst(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123));
|
||||||
|
Build(R"(error: cyclic dependency found: 'SYMBOL' -> 'SYMBOL'
|
||||||
|
12:34 note: let 'SYMBOL' references let 'SYMBOL' here)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverDependencyGraphDeclSelfUse, LocalVar) {
|
||||||
|
const Symbol symbol = Sym("SYMBOL");
|
||||||
|
WrapInFunction(
|
||||||
|
Decl(Var(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123))));
|
||||||
|
Build("12:34 error: unknown identifier: 'SYMBOL'");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverDependencyGraphDeclSelfUse, LocalLet) {
|
||||||
|
const Symbol symbol = Sym("SYMBOL");
|
||||||
|
WrapInFunction(
|
||||||
|
Decl(Const(symbol, ty.i32(), Mul(Expr(Source{{12, 34}}, symbol), 123))));
|
||||||
|
Build("12:34 error: unknown identifier: 'SYMBOL'");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace undeclared_tests
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Recursive dependency tests
|
// Recursive dependency tests
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue