Skip to content

Commit

Permalink
Flip the default value of --incompatible_disallow_slash_operator
Browse files Browse the repository at this point in the history
Fixes #5823

RELNOTES: --incompatible_disallow_slash_operator is now on by default
PiperOrigin-RevId: 221127591
  • Loading branch information
laurentlb authored and Copybara-Service committed Nov 12, 2018
1 parent 64a111e commit 58dab6c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion site/docs/skylark/backward-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ x = 7 // 2 # x is 3
```

* Flag: `--incompatible_disallow_slash_operator`
* Default: `false`
* Default: `true`
* Tracking issue: [#5823](https://github.com/bazelbuild/bazel/issues/5823)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,15 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable
public boolean incompatibleGenerateJavaCommonSourceJar;

@Option(
name = "incompatible_disallow_slash_operator",
defaultValue = "false",
name = "incompatible_disallow_slash_operator",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.SKYLARK_SEMANTICS,
effectTags = {OptionEffectTag.BUILD_FILE_SEMANTICS},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "If set to true, the `/` operator is disabled. Use `//` for integer division."
)
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "If set to true, the `/` operator is disabled. Use `//` for integer division.")
public boolean incompatibleDisallowSlashOperator;

/** Controls legacy arguments to ctx.actions.Args#add. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private static Object divide(Object lval, Object rval, Location location) throws
// We want to follow Python semantics, so we use float division and round down.
return (int) Math.floor(Double.valueOf((Integer) lval) / (Integer) rval);
}
throw typeException(lval, rval, Operator.DIVIDE, location);
throw typeException(lval, rval, Operator.FLOOR_DIVIDE, location);
}

/** Implements Operator.PERCENT. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static Builder builderWithDefaults() {
.incompatibleDisallowLegacyJavaInfo(false)
.incompatibleDisallowLoadLabelsToCrossPackageBoundaries(false)
.incompatibleDisallowOldStyleArgsAdd(false)
.incompatibleDisallowSlashOperator(false)
.incompatibleDisallowSlashOperator(true)
.incompatibleExpandDirectories(false)
.incompatibleGenerateJavaCommonSourceJar(false)
.incompatibleNewActionsApi(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public void aspectFailingExecution() throws Exception {
scratch.file(
"test/aspect.bzl",
"def _impl(target, ctx):",
" return 1/0",
" return 1 // 0",
"",
"MyAspect = aspect(implementation=_impl)");
scratch.file("test/BUILD", "java_library(name = 'xxx',)");
Expand All @@ -847,7 +847,7 @@ public void aspectFailingExecution() throws Exception {
+ LINE_SEPARATOR
+ "\tFile \"/workspace/test/aspect.bzl\", line 2, in _impl"
+ LINE_SEPARATOR
+ "\t\t1 / 0"
+ "\t\t1 // 0"
+ LINE_SEPARATOR
+ "integer division by zero");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ public void testLoadSucceedsDespiteSyntaxError() throws Exception {
"test/skylark/BUILD",
"load('//test/skylark:macro.bzl', 'x')",
"pass", // syntax error
"print(1 / (5 - x)"); // division by 0
"print(1 // (5 - x)"); // division by 0

// Make sure that evaluation continues and load() succeeds, despite a syntax
// error in the file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void testDivision() throws Exception {
.testStatement("-7 / 2", -4)
.testStatement("-7 / -2", 3)
.testStatement("2147483647 / 2", 1073741823)
.testIfErrorContains("unsupported operand type(s) for /: 'string' and 'int'", "'str' / 2")
.testIfErrorContains("unsupported operand type(s) for //: 'string' and 'int'", "'str' / 2")
.testIfExactError("integer division by zero", "5 / 0");
}

Expand All @@ -224,7 +224,7 @@ public void testFloorDivision() throws Exception {
.testStatement("-7 // 2", -4)
.testStatement("-7 // -2", 3)
.testStatement("2147483647 // 2", 1073741823)
.testIfErrorContains("unsupported operand type(s) for /: 'string' and 'int'", "'str' / 2")
.testIfErrorContains("unsupported operand type(s) for //: 'string' and 'int'", "'str' // 2")
.testIfExactError("integer division by zero", "5 // 0");
}

Expand All @@ -244,8 +244,8 @@ public void testCheckedArithmetic() throws Exception {
public void testOperatorPrecedence() throws Exception {
newTest()
.testStatement("2 + 3 * 4", 14)
.testStatement("2 + 3 / 4", 2)
.testStatement("2 * 3 + 4 / -2", 4);
.testStatement("2 + 3 // 4", 2)
.testStatement("2 * 3 + 4 // -2", 4);
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/skylark/testdata/int.sky
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ assert_eq(-98 % -7, 0)

# precedence
assert_eq(5 - 7 * 2 + 3, -6)
assert_eq(4 * 5 / 2 + 5 / 2 * 4, 18)
assert_eq(4 * 5 // 2 + 5 // 2 * 4, 18)

# compound assignment
def compound():
Expand All @@ -53,14 +53,14 @@ def compound():
assert_eq(x, -1)
x *= 10
assert_eq(x, -10)
x /= -2
x //= -2
assert_eq(x, 5)
x %= 3
assert_eq(x, 2)

compound()

---
1 / 0 ### integer division by zero
1 // 0 ### integer division by zero
---
1 % 0 ### integer modulo by zero

0 comments on commit 58dab6c

Please sign in to comment.