From 6aa2f64045d390f4da77d396cd3fcbe1c44a98c1 Mon Sep 17 00:00:00 2001 From: Jon Brandvein Date: Thu, 4 Aug 2016 20:17:28 +0000 Subject: Fix Environment.Continuation's tracking of global variables RELNOTES[INC]: Skylark: It is an error to shadow a global variable with a local variable after the global has already been accessed in the function. -- MOS_MIGRATED_REVID=129365195 --- .../com/google/devtools/build/lib/syntax/FunctionTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java') diff --git a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java index d5d393702b..3451238e01 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java @@ -119,6 +119,18 @@ public class FunctionTest extends EvaluationTestCase { "c = func()\n"); } + @Test + public void testFunctionDefLocalVariableReferencedInCallBeforeAssignment() throws Exception { + checkEvalErrorContains("Variable 'a' is referenced before assignment.", + "def dummy(x):", + " pass", + "a = 1", + "def func():", + " dummy(a)", + " a = 2", + "func()\n"); + } + @Test public void testFunctionDefLocalVariableReferencedAfterAssignment() throws Exception { eval("a = 1", -- cgit v1.2.3