diff --git a/src/resolver/dependency_graph.cc b/src/resolver/dependency_graph.cc index 2d92343d7e..2de794fce9 100644 --- a/src/resolver/dependency_graph.cc +++ b/src/resolver/dependency_graph.cc @@ -227,7 +227,6 @@ class DependencyScanner { if (auto* l = stmt->As()) { scope_stack_.Push(); TINT_DEFER(scope_stack_.Pop()); - TraverseStatements(l->body->statements); TraverseStatement(l->continuing); return; @@ -256,9 +255,9 @@ class DependencyScanner { return; } if (auto* v = stmt->As()) { - Declare(v->variable->symbol, v->variable); TraverseType(v->variable->type); TraverseExpression(v->variable->constructor); + Declare(v->variable->symbol, v->variable); return; } if (stmt->IsAnyOf '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 ////////////////////////////////////////////////////////////////////////////////