bazel packages: existing_rule: convert Tristate to StarlarkInt (not Integer)
RELNOTES: N/A
@@ -47,6 +47,7 @@ import net.starlark.java.eval.Mutability;
import net.starlark.java.eval.NoneType;
import net.starlark.java.eval.Sequence;
import net.starlark.java.eval.Starlark;
+import net.starlark.java.eval.StarlarkInt;
import net.starlark.java.eval.StarlarkList;
import net.starlark.java.eval.StarlarkThread;
import net.starlark.java.eval.StarlarkValue;
@@ -329,27 +330,22 @@ public class StarlarkNativeModule implements StarlarkNativeModuleApi {
@Nullable
private static Object starlarkifyValue(Mutability mu, Object val, Package pkg)
throws NotRepresentableException {
- if (val == null) {
- return null;
- }
- if (val instanceof Boolean) {
- return val;
- }
- if (val instanceof Integer) {
- return val;
- }
- if (val instanceof String) {
+ // easy cases
+ if (val == null
+ || val instanceof Boolean
+ || val instanceof String
+ || val instanceof StarlarkInt) {
return val;
}
if (val instanceof TriState) {
switch ((TriState) val) {
case AUTO:
- return -1;
+ return StarlarkInt.of(-1);
case YES:
- return 1;
+ return StarlarkInt.of(1);
case NO:
- return 0;
+ return StarlarkInt.of(0);
}
}
