Introduce --incompatible_disallow_toplevel_if_statement to forbid top-level if statements.

RELNOTES:
  In .bzl files, top-level `if` statements are deprecated and will be forbidden
  in the future. Move them in a function body instead (or use a conditional
  expression instead: `x if condition else y`).
PiperOrigin-RevId: 158276986
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 0ad0297..10c80c7 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
@@ -60,6 +60,18 @@
   }
 
   @Test
+  public void testForbiddenToplevelIfStatement() throws Exception {
+    env = newEnvironmentWithSkylarkOptions("--incompatible_disallow_toplevel_if_statement=true");
+    checkError("if statements are not allowed at the top level", "if True: a = 2");
+  }
+
+  @Test
+  public void testAllowedToplevelIfStatement() throws Exception {
+    env = newEnvironmentWithSkylarkOptions("--incompatible_disallow_toplevel_if_statement=false");
+    parse("if True: a = 5");
+  }
+
+  @Test
   public void testTwoFunctionsWithTheSameName() throws Exception {
     checkError(
         "Variable foo is read only", "def foo():", "  return 1", "def foo(x, y):", "  return 1");