diff options
author | 2017-08-28 17:50:51 +0200 | |
---|---|---|
committer | 2017-08-29 13:31:10 +0200 | |
commit | 6ccff29c57c9795d93eec496fdc7cfc3c135d58a (patch) | |
tree | 26c6fbcc9480c86862d0fecb00ff450e5c847090 /src/test/java/com/google/devtools/build/lib | |
parent | c1309787cc4b55cb1d11e60a687f27b9b38ed09c (diff) |
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
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java | 2 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/ValidationTest.java | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java index 79afdb9703..39f46d03b2 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SyntaxTreeVisitorTest.java @@ -62,7 +62,7 @@ public class SyntaxTreeVisitorTest { " return h + i.j()"); IdentVisitor visitor = new IdentVisitor(); ast.accept(visitor); - assertThat(idents).containsExactly("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").inOrder(); + assertThat(idents).containsExactly("b", "a", "c", "e", "d", "f", "g", "h", "i", "j").inOrder(); assertThat(params).containsExactly("p1", "p2=4", "**p3").inOrder(); } } 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 604c53fe4b..49f5dbb293 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 @@ public class ValidationTest extends EvaluationTestCase { } @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"); } |