From ee250c6e9e7e24761ff26d3ee225ad485a7facf3 Mon Sep 17 00:00:00 2001 From: laurentlb Date: Thu, 7 Sep 2017 19:17:52 +0200 Subject: --incompatible_comprehension_variables_do_not_leak defaults to true RELNOTES[INC]: --incompatible_comprehension_variables_do_not_leak defaults to "true." Iteration variable becomes inaccessible after a list/dict comprehension. PiperOrigin-RevId: 167876119 --- .../com/google/devtools/build/lib/syntax/EvaluationTest.java | 10 ++++------ .../devtools/build/lib/syntax/SkylarkEvaluationTest.java | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/test/java/com/google/devtools') diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java index fb438a6e70..ae21bee88a 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java @@ -406,12 +406,10 @@ public class EvaluationTest extends EvaluationTestCase { } @Test - public void testListComprehensionModifiesGlobalEnv() throws Exception { - new SkylarkTest() - .update("x", 42) - .testIfErrorContains("Variable x is read only", "[x + 1 for x in [1,2,3]]"); - new BuildTest().update("x", 42).setUp("y =[x + 1 for x in [1,2,3]]") - .testExactOrder("y", 2, 3, 4).testLookup("x", 3); // (x is global) + public void testListComprehensionAtTopLevel() throws Exception { + // It is allowed to have a loop variable with the same name as a global variable. + newTest().update("x", 42).setUp("y = [x + 1 for x in [1,2,3]]") + .testExactOrder("y", 2, 3, 4); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java index e27cb6372f..7ab15c9d87 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java @@ -1384,11 +1384,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { + "evaluates to value of length 2", "[x + y for x, y, z in [(1, 2), (3, 4)]]"); - // can't reuse the same local variable twice(!) - new SkylarkTest() - .testIfErrorContains( - "Variable x is read only", "[x + y for x, y in (1, 2)]", "[x + y for x, y in (1, 2)]"); - new SkylarkTest() .testIfErrorContains("type 'int' is not a collection", "[x2 + y2 for x2, y2 in (1, 2)]"); -- cgit v1.2.3