Visit subtrees of the AST in evaluation order
For instance, it makes more sense to visit the RHS of an assignment
first because this is evaluated first.
This also fixes a bug in the validator, which allowed definitions
like "a = a"
RELNOTES: None
PiperOrigin-RevId: 166709589
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
index 604c53f..49f5dbb 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java
@@ -105,6 +105,14 @@
}
@Test
+ public void testDefinitionByItself() throws Exception {
+ checkError("name 'a' is not defined", "a = a");
+ checkError("name 'a' is not defined", "a += a");
+ checkError("name 'a' is not defined", "[[] for a in a]");
+ checkError("name 'a' is not defined", "def f():", " for a in a: pass");
+ }
+
+ @Test
public void testLocalValidationEnvironmentsAreSeparated() throws Exception {
parse("def func1():", " a = 1", "def func2():", " a = 'abc'\n");
}