Flip the flag "--incompatible_static_name_resolution"
This is an incompatible change, but it breaks in a single case:
global = 2
def fct(x):
if x:
global = 3
print(global)
Before the change, `global` would refer to either the global variable
or the local variable, depending on the value of `x`. After the change,
it is either `3` or undefined (runtime error).
Fixes #5637
RELNOTES: --incompatible_static_name_resolution is no unable by default
PiperOrigin-RevId: 222242205
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 ad30f46..e2325ce 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
@@ -1785,7 +1785,7 @@
public void testFunctionCallBadOrdering() throws Exception {
new SkylarkTest()
.testIfErrorContains(
- "name 'foo' is not defined",
+ "global variable 'foo' is referenced before assignment.",
"def func(): return foo() * 2",
"x = func()",
"def foo(): return 2");
@@ -2207,7 +2207,9 @@
@Test
public void testListComprehensionsDoNotLeakVariables() throws Exception {
checkEvalErrorContains(
- "name 'a' is not defined",
+ // TODO(laurentlb): This happens because the variable gets undefined after the list
+ // comprehension. We should do better.
+ "local variable 'a' is referenced before assignment.",
"def foo():",
" a = 10",
" b = [a for a in range(3)]",