bazel syntax: remove depset special case in Starlark.type
Every place that wanted the "depset of T" message was either
already using Depset.cast, or doing its own thing (Py, Objc).
The fullDetails parameter has been deleted.
This breaks one more dependency from the interpreter to Depset.
Also:
- remove EvalUtils.getDataTypeName (use Starlark.type instead)
- rename EvalUtils.getDataTypeNameFromClass to Starlark.classType
(The highlightNamespaces parameter was always true; deleted.)
PiperOrigin-RevId: 309067985
diff --git a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkConstructorMethodDoc.java b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkConstructorMethodDoc.java
index 7217c51..3ba206d 100644
--- a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkConstructorMethodDoc.java
+++ b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkConstructorMethodDoc.java
@@ -16,7 +16,7 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.StarlarkDeprecated;
-import com.google.devtools.build.lib.syntax.EvalUtils;
+import com.google.devtools.build.lib.syntax.Starlark;
import java.lang.reflect.Method;
import java.util.List;
@@ -85,7 +85,7 @@
@Override
public String getReturnType() {
- return EvalUtils.getDataTypeNameFromClass(method.getReturnType());
+ return Starlark.classType(method.getReturnType());
}
@Override
diff --git a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkDoc.java b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkDoc.java
index bb76914..297c70d 100644
--- a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkDoc.java
+++ b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkDoc.java
@@ -19,9 +19,9 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.NoneType;
import com.google.devtools.build.lib.syntax.Sequence;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkList;
import com.google.devtools.build.lib.syntax.Tuple;
import java.lang.reflect.Method;
@@ -75,7 +75,7 @@
module.name());
}
}
- return EvalUtils.getDataTypeNameFromClass(type);
+ return Starlark.classType(type);
}
// Omit self parameter from parameters in class methods.
diff --git a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkJavaMethodDoc.java b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkJavaMethodDoc.java
index f41c105..80179ea 100644
--- a/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkJavaMethodDoc.java
+++ b/src/main/java/com/google/devtools/build/docgen/starlark/StarlarkJavaMethodDoc.java
@@ -19,7 +19,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.StarlarkDeprecated;
-import com.google.devtools.build.lib.syntax.EvalUtils;
+import com.google.devtools.build.lib.syntax.Starlark;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -131,7 +131,7 @@
@Override
public String getReturnType() {
- return EvalUtils.getDataTypeNameFromClass(method.getReturnType());
+ return Starlark.classType(method.getReturnType());
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
index bcc1c75..1309d83 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/platform/ConstraintCollection.java
@@ -33,7 +33,6 @@
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skylarkbuildapi.platform.ConstraintCollectionApi;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
@@ -172,7 +171,7 @@
if (!(key instanceof ConstraintSettingInfo)) {
throw Starlark.errorf(
"Constraint names must be platform_common.ConstraintSettingInfo, got %s instead",
- EvalUtils.getDataTypeName(key));
+ Starlark.type(key));
}
return (ConstraintSettingInfo) key;
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
index e30cc45..101c2f0 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
@@ -80,7 +80,6 @@
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleFunctionsApi;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Identifier;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Module;
@@ -384,7 +383,7 @@
throw Starlark.errorf(
"Illegal argument: element in 'provides' is of unexpected type. "
+ "Should be list of providers, but got item of type %s.",
- EvalUtils.getDataTypeName(o, true));
+ Starlark.type(o));
}
}
for (StarlarkProviderIdentifier skylarkProvider :
@@ -555,7 +554,7 @@
String.format(
"Illegal argument: element in 'provides' is of unexpected type. "
+ "Should be list of providers, but got item of type %s. ",
- EvalUtils.getDataTypeName(o, true)));
+ Starlark.type(o)));
}
}
return new SkylarkDefinedAspect(
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java
index 71027bb..33d45ae 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleConfiguredTargetUtil.java
@@ -54,7 +54,6 @@
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.syntax.Sequence;
@@ -145,8 +144,7 @@
&& !(target instanceof Iterable)) {
ruleContext.ruleError(
String.format(
- "Rule should return a struct or a list, but got %s",
- EvalUtils.getDataTypeName(target)));
+ "Rule should return a struct or a list, but got %s", Starlark.type(target)));
return null;
} else if (!expectFailure.isEmpty()) {
ruleContext.ruleError("Expected failure not found: " + expectFailure);
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
index 03a8d49..65fb4bf 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
@@ -1129,7 +1129,7 @@
} else {
throw Starlark.errorf(
"invalid value %s in 'label_dict': expected iterable, but got '%s'",
- Starlark.repr(val), EvalUtils.getDataTypeName(val));
+ Starlark.repr(val), Starlark.type(val));
}
for (Object file : valIter) {
if (!(file instanceof Artifact)) {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkActionFactory.java
index 9f5f01d..1c6d639 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkActionFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkActionFactory.java
@@ -53,7 +53,6 @@
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
@@ -410,7 +409,7 @@
throw new EvalException(
null,
"expected string or list of strings for command instead of "
- + EvalUtils.getDataTypeName(commandUnchecked));
+ + Starlark.type(commandUnchecked));
}
if (argumentList.size() > 0) {
// When we use a shell command, add an empty argument before other arguments.
@@ -451,7 +450,7 @@
throw new EvalException(
null,
"expected list of strings or ctx.actions.args() for arguments instead of "
- + EvalUtils.getDataTypeName(value));
+ + Starlark.type(value));
}
}
if (!stringArgs.isEmpty()) {
@@ -506,7 +505,7 @@
throw Starlark.errorf(
"expected value of type 'File' for a member of parameter 'unused_inputs_list' but got"
+ " %s instead",
- EvalUtils.getDataTypeName(unusedInputsList));
+ Starlark.type(unusedInputsList));
}
}
@@ -531,7 +530,7 @@
null,
"expected value of type 'File or FilesToRunProvider' for "
+ "a member of parameter 'tools' but got "
- + EvalUtils.getDataTypeName(toolUnchecked)
+ + Starlark.type(toolUnchecked)
+ " instead");
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkAttrModule.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkAttrModule.java
index 31cb6c7..b29fea1 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkAttrModule.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkAttrModule.java
@@ -363,21 +363,14 @@
for (Object o : starlarkList) {
if (!(o instanceof Sequence)) {
throw new EvalException(
- null,
- String.format(
- errorMsg,
- PROVIDERS_ARG,
- "an element of type " + EvalUtils.getDataTypeName(o, true)));
+ null, String.format(errorMsg, PROVIDERS_ARG, "an element of type " + Starlark.type(o)));
}
for (Object value : (Sequence) o) {
if (!isProvider(value)) {
throw new EvalException(
null,
String.format(
- errorMsg,
- argumentName,
- "list with an element of type "
- + EvalUtils.getDataTypeNameFromClass(value.getClass())));
+ errorMsg, argumentName, "list with an element of type " + Starlark.type(value)));
}
}
providersList.add(getStarlarkProviderIdentifiers((Sequence<?>) o));
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
index 46d93d5..bb0a94d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
@@ -54,7 +54,6 @@
import com.google.devtools.build.lib.skylarkbuildapi.repository.SkylarkRepositoryContextApi;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.syntax.Sequence;
@@ -1003,7 +1002,7 @@
String.format(
"Expected a string or sequence of strings for 'url' argument, "
+ "but got '%s' item in the sequence",
- EvalUtils.getDataTypeName(o)));
+ Starlark.type(o)));
}
result.add((String) o);
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index a91d460..719dd09 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -1482,8 +1482,7 @@
try {
return type.cast((result == Starlark.NONE) ? type.getDefaultValue() : result);
} catch (ClassCastException ex) {
- throw Starlark.errorf(
- "expected '%s', but got '%s'", type, EvalUtils.getDataTypeName(result, true));
+ throw Starlark.errorf("expected '%s', but got '%s'", type, Starlark.type(result));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java b/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
index 26bd781..79071c5 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/StructImpl.java
@@ -20,7 +20,6 @@
import com.google.devtools.build.lib.syntax.ClassObject;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Sequence;
@@ -88,8 +87,7 @@
@SuppressWarnings("UnusedException")
ClassCastException unused) {
throw Starlark.errorf(
- "for %s field, got %s, want %s",
- key, Starlark.type(obj), EvalUtils.getDataTypeNameFromClass(type));
+ "for %s field, got %s, want %s", key, Starlark.type(obj), Starlark.classType(type));
}
}
@@ -220,7 +218,7 @@
throw Starlark.errorf(
"Invalid text format, expected a struct, a dict, a string, a bool, or an int but got a"
+ " %s for %s '%s'",
- EvalUtils.getDataTypeName(value), container, key);
+ Starlark.type(value), container, key);
}
}
@@ -290,9 +288,7 @@
if (!(entry.getKey() instanceof String)) {
throw Starlark.errorf(
"Keys must be a string but got a %s for %s%s",
- EvalUtils.getDataTypeName(entry.getKey()),
- container,
- key != null ? " '" + key + "'" : "");
+ Starlark.type(entry.getKey()), container, key != null ? " '" + key + "'" : "");
}
appendJSONStringLiteral(sb, (String) entry.getKey());
sb.append(':');
@@ -316,7 +312,7 @@
throw Starlark.errorf(
"Invalid text format, expected a struct, a string, a bool, or an int but got a %s for"
+ " %s%s",
- EvalUtils.getDataTypeName(value), container, key != null ? " '" + key + "'" : "");
+ Starlark.type(value), container, key != null ? " '" + key + "'" : "");
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Type.java b/src/main/java/com/google/devtools/build/lib/packages/Type.java
index ec0f779..3df2a7e 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Type.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Type.java
@@ -28,6 +28,7 @@
import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Sequence;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.util.LoggingUtil;
import com.google.devtools.build.lib.util.StringCanonicalizer;
import java.util.ArrayList;
@@ -248,7 +249,7 @@
}
printer.append(", but got ");
printer.repr(value);
- printer.append(" (").append(EvalUtils.getDataTypeName(value)).append(")");
+ printer.append(" (").append(Starlark.type(value)).append(")");
return printer.toString();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
index f2ed2dd..62531aa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
@@ -964,7 +964,7 @@
+ " of type '%s' instead of a '%s' provider. Use the methods provided in"
+ " https://source.bazel.build/bazel/+/master:tools/cpp/cc_toolchain_config_lib.bzl"
+ " for obtaining the right providers.",
- parameterName, EvalUtils.getDataTypeName(o), expectedProvider);
+ parameterName, Starlark.type(o), expectedProvider);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java
index 07db1b6..32f841a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java
@@ -68,10 +68,6 @@
+ " 'strict_include', 'providers', or 'direct_dep_providers'.";
@VisibleForTesting
- public static final String BAD_SET_TYPE_ERROR =
- "Value for key %s must be a set of %s, instead found %s.";
-
- @VisibleForTesting
public static final String BAD_FRAMEWORK_PATH_ERROR =
"Value for key framework_search_paths must end in .framework; instead found %s.";
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java
index b7428aa..e6ed657 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java
@@ -41,8 +41,8 @@
import com.google.devtools.build.lib.skylarkbuildapi.apple.ObjcProviderApi;
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Sequence;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkList;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -1244,9 +1244,7 @@
void addProvidersFromSkylark(Object toAdd) throws EvalException {
if (!(toAdd instanceof Iterable)) {
throw new EvalException(
- null,
- String.format(
- AppleSkylarkCommon.BAD_PROVIDERS_ITER_ERROR, EvalUtils.getDataTypeName(toAdd)));
+ null, String.format(AppleSkylarkCommon.BAD_PROVIDERS_ITER_ERROR, Starlark.type(toAdd)));
} else {
Iterable<Object> toAddIterable = (Iterable<Object>) toAdd;
for (Object toAddObject : toAddIterable) {
@@ -1254,8 +1252,7 @@
throw new EvalException(
null,
String.format(
- AppleSkylarkCommon.BAD_PROVIDERS_ELEM_ERROR,
- EvalUtils.getDataTypeName(toAddObject)));
+ AppleSkylarkCommon.BAD_PROVIDERS_ELEM_ERROR, Starlark.type(toAddObject)));
} else {
ObjcProvider objcProvider = (ObjcProvider) toAddObject;
this.addTransitiveAndPropagate(objcProvider);
@@ -1274,9 +1271,7 @@
void addDirectDepProvidersFromSkylark(Object toAdd) throws EvalException {
if (!(toAdd instanceof Iterable)) {
throw new EvalException(
- null,
- String.format(
- AppleSkylarkCommon.BAD_PROVIDERS_ITER_ERROR, EvalUtils.getDataTypeName(toAdd)));
+ null, String.format(AppleSkylarkCommon.BAD_PROVIDERS_ITER_ERROR, Starlark.type(toAdd)));
} else {
Iterable<Object> toAddIterable = (Iterable<Object>) toAdd;
for (Object toAddObject : toAddIterable) {
@@ -1284,8 +1279,7 @@
throw new EvalException(
null,
String.format(
- AppleSkylarkCommon.BAD_PROVIDERS_ELEM_ERROR,
- EvalUtils.getDataTypeName(toAddObject)));
+ AppleSkylarkCommon.BAD_PROVIDERS_ELEM_ERROR, Starlark.type(toAddObject)));
} else {
this.addAsDirectDeps((ObjcProvider) toAddObject);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java
index b93154d..a5e19c4 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProviderSkylarkConverters.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.objc;
-import static com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon.BAD_SET_TYPE_ERROR;
import static com.google.devtools.build.lib.rules.objc.AppleSkylarkCommon.NOT_SET_ERROR;
import com.google.common.collect.ImmutableMap;
@@ -24,7 +23,7 @@
import com.google.devtools.build.lib.rules.objc.ObjcProvider.Key;
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.vfs.PathFragment;
/** A utility class for converting ObjcProvider values between java and Starlark representation. */
@@ -132,26 +131,12 @@
}
}
- /** Throws an error if the given object is not a nested set of the given type. */
- private static <T> NestedSet<T> nestedSetWithType(
- Object toCheck, Class<T> expectedSetType, String keyName) throws EvalException {
- if (toCheck instanceof Depset) {
- Depset sns = (Depset) toCheck;
- try {
- return sns.getSet(expectedSetType);
- } catch (Depset.TypeException exception) {
- throw new EvalException(
- null,
- String.format(
- BAD_SET_TYPE_ERROR,
- keyName,
- EvalUtils.getDataTypeNameFromClass(expectedSetType),
- EvalUtils.getDataTypeName(toCheck, /*fullDetails=*/ true)),
- exception);
- }
- } else {
- throw new EvalException(
- null, String.format(NOT_SET_ERROR, keyName, EvalUtils.getDataTypeName(toCheck)));
+ /** Throws EvalException if x is not a depset of the given type. */
+ private static <T> NestedSet<T> nestedSetWithType(Object x, Class<T> elemType, String what)
+ throws EvalException {
+ if (x == null) {
+ throw Starlark.errorf(NOT_SET_ERROR, what, Starlark.type(x));
}
+ return Depset.cast(x, elemType, what);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
index f561844..8ce3276 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
@@ -52,7 +52,7 @@
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -407,7 +407,7 @@
String.format(
"Error parsing the Python toolchain's ToolchainInfo: Expected a PyRuntimeInfo in "
+ "field '%s', but got '%s'",
- field, EvalUtils.getDataTypeName(fieldValue)));
+ field, Starlark.type(fieldValue)));
return null;
}
PyRuntimeInfo pyRuntimeInfo = (PyRuntimeInfo) fieldValue;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyInfo.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyInfo.java
index 6044d2b..1ef10dd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyInfo.java
@@ -25,7 +25,6 @@
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.Depset.TypeException;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Location;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkThread;
@@ -57,12 +56,14 @@
* <p>For depsets, this includes its content type and order.
*/
private static String describeType(Object value) {
- String typeName = EvalUtils.getDataTypeName(value, /*fullDetails=*/ true);
if (value instanceof Depset) {
- return ((Depset) value).getOrder().getSkylarkName() + "-ordered " + typeName;
- } else {
- return typeName;
+ Depset depset = (Depset) value;
+ return depset.getOrder().getSkylarkName()
+ + "-ordered depset of "
+ + depset.getElementType()
+ + "s";
}
+ return Starlark.type(value);
}
private final Location location;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java
index 1d152ec..851fdb8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkylarkAspectFactory.java
@@ -36,7 +36,6 @@
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.EvalExceptionWithStackTrace;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Mutability;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkThread;
@@ -107,7 +106,7 @@
String.format(
"Aspect implementation should return a struct, a list, or a provider "
+ "instance, but got %s",
- EvalUtils.getDataTypeName(aspectSkylarkObject)));
+ Starlark.type(aspectSkylarkObject)));
return null;
}
return createAspect(aspectSkylarkObject, ruleContext);
diff --git a/src/main/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerialization.java b/src/main/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerialization.java
index 0a5d760..806363ac4 100644
--- a/src/main/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerialization.java
+++ b/src/main/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerialization.java
@@ -23,7 +23,6 @@
import com.google.devtools.build.lib.syntax.ClassObject;
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import com.google.devtools.build.lib.syntax.StarlarkValue;
@@ -40,7 +39,7 @@
return Value.newBuilder()
.setLabel(label)
// TODO(bazel-team): omit type details for non-Starlark values
- .setType(EvalUtils.getDataTypeName(value))
+ .setType(Starlark.type(value))
.setDescription(getDescription(value))
.setHasChildren(hasChildren)
.setId(hasChildren ? objectMap.registerValue(value) : 0)
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinCallable.java b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinCallable.java
index 3cf5d46..a3689a8 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinCallable.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinCallable.java
@@ -336,10 +336,7 @@
if (!ok) {
throw Starlark.errorf(
"in call to %s(), parameter '%s' got value of type '%s', want '%s'",
- methodName,
- param.getName(),
- EvalUtils.getDataTypeName(value),
- param.getTypeErrorMessage());
+ methodName, param.getName(), Starlark.type(value), param.getTypeErrorMessage());
}
// None is valid if and only if the parameter is marked noneable,
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
index ad91b3e..5ab33bf 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
@@ -172,8 +172,7 @@
throws EvalException, InterruptedException {
MethodDescriptor desc = getCacheValue(x.getClass(), semantics).fields.get(fieldName);
if (desc == null) {
- throw Starlark.errorf(
- "value of type %s has no .%s field", EvalUtils.getDataTypeName(x), fieldName);
+ throw Starlark.errorf("value of type %s has no .%s field", Starlark.type(x), fieldName);
}
return desc.callField(x, semantics, /*mu=*/ null);
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Depset.java b/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
index 51c5956..9ccdd5e 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Depset.java
@@ -156,8 +156,7 @@
// Even the looser regime forbids the top-level class to be list or dict.
if (x instanceof StarlarkList || x instanceof Dict) {
- throw Starlark.errorf(
- "depsets cannot contain items of type '%s'", EvalUtils.getDataTypeName(x));
+ throw Starlark.errorf("depsets cannot contain items of type '%s'", Starlark.type(x));
}
}
@@ -220,7 +219,7 @@
throw new TypeException(
String.format(
"got a depset of '%s', expected a depset of '%s'",
- elemType, EvalUtils.getDataTypeNameFromClass(type)));
+ elemType, Starlark.classType(type)));
}
@SuppressWarnings("unchecked")
NestedSet<T> res = (NestedSet<T>) set;
@@ -266,8 +265,7 @@
public static <T> NestedSet<T> cast(Object x, Class<T> type, String what) throws EvalException {
if (!(x instanceof Depset)) {
throw Starlark.errorf(
- "for %s, got %s, want a depset of %s",
- what, EvalUtils.getDataTypeName(x, true), EvalUtils.getDataTypeNameFromClass(type));
+ "for %s, got %s, want a depset of %s", what, Starlark.type(x), Starlark.classType(type));
}
try {
return ((Depset) x).getSet(type);
@@ -432,7 +430,7 @@
@Override
public String toString() {
- return cls == null ? "empty" : EvalUtils.getDataTypeNameFromClass(cls);
+ return cls == null ? "empty" : Starlark.classType(cls);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Dict.java b/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
index 3c70d4e..e396fc2 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Dict.java
@@ -500,8 +500,8 @@
Starlark.type(e.getKey()),
Starlark.type(e.getValue()),
what,
- EvalUtils.getDataTypeNameFromClass(keyType),
- EvalUtils.getDataTypeNameFromClass(valueType));
+ Starlark.classType(keyType),
+ Starlark.classType(valueType));
}
}
@@ -548,8 +548,7 @@
try {
seq = Starlark.toIterable(args);
} catch (EvalException ex) {
- throw Starlark.errorf(
- "in %s, got %s, want iterable", funcname, EvalUtils.getDataTypeName(args));
+ throw Starlark.errorf("in %s, got %s, want iterable", funcname, Starlark.type(args));
}
Dict<K, V> result = Dict.of(mu);
int pos = 0;
@@ -560,7 +559,7 @@
} catch (EvalException ex) {
throw Starlark.errorf(
"in %s, dictionary update sequence element #%d is not iterable (%s)",
- funcname, pos, EvalUtils.getDataTypeName(item));
+ funcname, pos, Starlark.type(item));
}
// TODO(adonovan): opt: avoid unnecessary allocations and copies.
// Why is there no operator to compute len(x), following the spec, without iterating??
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
index 457ad17..e5cec40 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/EvalUtils.java
@@ -17,12 +17,8 @@
import com.google.common.base.Strings;
import com.google.common.collect.Ordering;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.starlark.spelling.SpellChecker;
import java.util.IllegalFormatException;
-import java.util.List;
-import java.util.Map;
/** Utilities used by the evaluator. */
// TODO(adonovan): move all fundamental values and operators of the language to Starlark
@@ -169,73 +165,6 @@
|| c.equals(Boolean.class);
}
- /**
- * Returns a pretty name for the datatype of object 'o' in the Build language.
- */
- public static String getDataTypeName(Object o) {
- return getDataTypeName(o, false);
- }
-
- /**
- * Returns a pretty name for the datatype of object {@code object} in Starlark or the BUILD
- * language, with full details if the {@code full} boolean is true.
- */
- public static String getDataTypeName(Object object, boolean fullDetails) {
- Preconditions.checkNotNull(object);
- if (fullDetails) {
- if (object instanceof Depset) {
- Depset set = (Depset) object;
- return "depset of " + set.getElementType() + "s";
- }
- }
- return getDataTypeNameFromClass(object.getClass());
- }
-
- /**
- * Returns a pretty name for the datatype equivalent of class 'c' in the Build language.
- */
- public static String getDataTypeNameFromClass(Class<?> c) {
- return getDataTypeNameFromClass(c, true);
- }
-
- /**
- * Returns a pretty name for the datatype equivalent of class 'c' in the Build language.
- *
- * @param highlightNameSpaces Determines whether the result should also contain a special comment
- * when the given class identifies a Starlark name space.
- */
- // TODO(adonovan): document that this function accepts (and must accept) any Java class,
- // not just those corresponding to legal Starlark value classes, or even their supertypes.
- private static String getDataTypeNameFromClass(Class<?> c, boolean highlightNameSpaces) {
- // Check for "direct hits" first to avoid needing to scan for annotations.
- if (c.equals(String.class)) {
- return "string";
- } else if (c.equals(Integer.class)) {
- return "int";
- } else if (c.equals(Boolean.class)) {
- return "bool";
- }
-
- SkylarkModule module = SkylarkInterfaceUtils.getSkylarkModule(c);
- if (module != null) {
- return module.namespace() && highlightNameSpaces
- ? module.name() + " (a language module)"
- : module.name();
- } else if (List.class.isAssignableFrom(c)) { // This is a Java List that isn't a Sequence
- return "List"; // This case shouldn't happen in normal code, but we keep it for debugging.
- } else if (Map.class.isAssignableFrom(c)) { // This is a Java Map that isn't a Dict
- return "Map"; // This case shouldn't happen in normal code, but we keep it for debugging.
- } else if (StarlarkCallable.class.isAssignableFrom(c)) {
- // TODO(adonovan): each StarlarkCallable should report its own type string.
- return "function";
- } else if (c.equals(Object.class)) {
- return "unknown";
- } else {
- String simpleName = c.getSimpleName();
- return simpleName.isEmpty() ? c.getName() : simpleName;
- }
- }
-
static void addIterator(Object x) {
if (x instanceof Mutability.Freezable) {
((Mutability.Freezable) x).updateIteratorCount(+1);
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
index 1dfc027..5212b91 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
@@ -207,8 +207,7 @@
throw (EvalException) comp.e;
}
} else {
- throw Starlark.errorf(
- "%s object is not callable", Starlark.repr(EvalUtils.getDataTypeName(key)));
+ throw Starlark.errorf("%s object is not callable", Starlark.repr(Starlark.type(key)));
}
if (reverse) {
@@ -282,7 +281,7 @@
public Integer len(Object x, StarlarkThread thread) throws EvalException {
int len = Starlark.len(x);
if (len < 0) {
- throw Starlark.errorf("%s is not iterable", EvalUtils.getDataTypeName(x));
+ throw Starlark.errorf("%s is not iterable", Starlark.type(x));
}
return len;
}
@@ -408,8 +407,7 @@
if (base == Starlark.UNBOUND) {
base = 10;
} else if (!(base instanceof Integer)) {
- throw Starlark.errorf(
- "base must be an integer (got '%s')", EvalUtils.getDataTypeName(base));
+ throw Starlark.errorf("base must be an integer (got '%s')", Starlark.type(base));
}
return fromString((String) x, (Integer) base);
} else {
@@ -608,7 +606,7 @@
start = startOrStop;
stop = (Integer) stopOrNone;
} else {
- throw Starlark.errorf("want int, got %s", EvalUtils.getDataTypeName(stopOrNone));
+ throw Starlark.errorf("want int, got %s", Starlark.type(stopOrNone));
}
if (step == 0) {
throw Starlark.errorf("step cannot be 0");
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java b/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
index 654ba0c..6277667 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/ParamDescriptor.java
@@ -104,9 +104,7 @@
/** Returns a description of allowed argument types suitable for an error message. */
String getTypeErrorMessage() {
- return allowedClasses.stream()
- .map(EvalUtils::getDataTypeNameFromClass)
- .collect(Collectors.joining(" or "));
+ return allowedClasses.stream().map(Starlark::classType).collect(Collectors.joining(" or "));
}
List<Class<?>> getAllowedClasses() {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
index 838a588..223a7dd 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Printer.java
@@ -281,22 +281,22 @@
// -- non-Starlark values --
- } else if (o instanceof Map<?, ?>) {
+ } else if (o instanceof Map) {
Map<?, ?> dict = (Map<?, ?>) o;
this.printList(dict.entrySet(), "{", ", ", "}", null);
- } else if (o instanceof List<?>) {
+ } else if (o instanceof List) {
List<?> seq = (List<?>) o;
this.printList(seq, false);
- } else if (o instanceof Map.Entry<?, ?>) {
+ } else if (o instanceof Map.Entry) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
this.repr(entry.getKey());
this.append(": ");
this.repr(entry.getValue());
- } else if (o instanceof Class<?>) {
- this.append(EvalUtils.getDataTypeNameFromClass((Class<?>) o));
+ } else if (o instanceof Class) {
+ this.append(Starlark.classType((Class<?>) o));
} else if (o instanceof Node || o instanceof Location) {
// AST node objects and locations are printed in tracebacks and error messages,
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java b/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
index 726a3ba..ab4d78b 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Sequence.java
@@ -87,7 +87,7 @@
if (!elemType.isAssignableFrom(elem.getClass())) {
throw Starlark.errorf(
"at index %d of %s, got element of type %s, want %s",
- i, what, Starlark.type(elem), EvalUtils.getDataTypeNameFromClass(elemType));
+ i, what, Starlark.type(elem), Starlark.classType(elemType));
}
}
@SuppressWarnings("unchecked") // safe
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java b/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
index 9a74be0..a11d7d1 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Starlark.java
@@ -214,7 +214,60 @@
/** Returns the name of the type of a value as if by the Starlark expression {@code type(x)}. */
public static String type(Object x) {
- return EvalUtils.getDataTypeName(x, false);
+ return classType(x.getClass());
+ }
+
+ /**
+ * Returns the name of the type of instances of class c.
+ *
+ * <p>This function accepts any class, not just those of legal Starlark values, and may be used
+ * for reporting error messages involving arbitrary Java classes, for example at the interface
+ * between Starlark and Java.
+ */
+ // TODO(adonovan): reconsider allowing any classes other than String, Integer, Boolean, and
+ // subclasses of StarlarkValue, with a special exception for Object.class meaning "any Starlark
+ // value" (not: any Java object). Ditto for Depset.ElementType.
+ public static String classType(Class<?> c) {
+ // Check for "direct hits" first to avoid needing to scan for annotations.
+ if (c.equals(String.class)) {
+ return "string";
+ } else if (c.equals(Integer.class)) {
+ return "int";
+ } else if (c.equals(Boolean.class)) {
+ return "bool";
+ }
+
+ SkylarkModule module = SkylarkInterfaceUtils.getSkylarkModule(c);
+ if (module != null) {
+ String name = module.name();
+ return module.namespace() ? name + " (a language module)" : name;
+
+ } else if (StarlarkCallable.class.isAssignableFrom(c)) {
+ // All callable values have historically been lumped together as "function".
+ // TODO(adonovan): built-in types that don't use SkylarkModule should report
+ // their own type string, but this is a breaking change as users often
+ // use type(x)=="function" for Starlark and built-in functions.
+ return "function";
+
+ } else if (c.equals(Object.class)) {
+ // "Unknown" is another unfortunate choice.
+ // Object.class does mean "unknown" when talking about the type parameter
+ // of a collection (List<Object>), but it also means "any" when used
+ // as an argument to Sequence.cast, and more generally it means "value".
+ return "unknown";
+
+ } else if (List.class.isAssignableFrom(c)) {
+ // Any class of java.util.List that isn't a Sequence.
+ return "List";
+
+ } else if (Map.class.isAssignableFrom(c)) {
+ // Any class of java.util.Map that isn't a Dict.
+ return "Map";
+
+ } else {
+ String simpleName = c.getSimpleName();
+ return simpleName.isEmpty() ? c.getName() : simpleName;
+ }
}
/** Returns the string form of a value as if by the Starlark expression {@code str(x)}. */
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java b/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
index cf7ac6c..f46ae15 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/StringModule.java
@@ -98,8 +98,7 @@
} else if (end instanceof Integer) {
stop = EvalUtils.toIndex((Integer) end, str.length());
} else {
- throw new EvalException(
- null, "expected int for " + what + ", got " + EvalUtils.getDataTypeName(end));
+ throw new EvalException(null, "expected int for " + what + ", got " + Starlark.type(end));
}
if (start >= stop) {
return "";
@@ -127,8 +126,7 @@
for (Object item : items) {
if (!(item instanceof String)) {
throw Starlark.errorf(
- "expected string for sequence element %d, got '%s'",
- i, EvalUtils.getDataTypeName(item));
+ "expected string for sequence element %d, got '%s'", i, Starlark.type(item));
}
i++;
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
index d942c23..b9fd5d9 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
@@ -714,7 +714,7 @@
@Test
public void testFilesetTypeDefinition() throws Exception {
- assertThat(EvalUtils.getDataTypeName(makeFilesetEntry())).isEqualTo("FilesetEntry");
+ assertThat(Starlark.type(makeFilesetEntry())).isEqualTo("FilesetEntry");
assertThat(EvalUtils.isImmutable(makeFilesetEntry())).isFalse();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java
index d29b30b..df029af 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcSkylarkTest.java
@@ -1322,9 +1322,7 @@
createObjcProviderSkylarkTarget(
" created_provider = apple_common.new_objc_provider(library='bar')",
" return created_provider"));
- assertThat(e)
- .hasMessageThat()
- .contains(String.format(AppleSkylarkCommon.NOT_SET_ERROR, "library", "string"));
+ assertThat(e).hasMessageThat().contains("for library, got string, want a depset of File");
}
@Test
@@ -1338,9 +1336,7 @@
" return created_provider"));
assertThat(e)
.hasMessageThat()
- .contains(
- String.format(
- AppleSkylarkCommon.BAD_SET_TYPE_ERROR, "library", "File", "depset of strings"));
+ .contains("for 'library', got a depset of 'string', expected a depset of 'File'");
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerializationTest.java b/src/test/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerializationTest.java
index 94151e3..287a933 100644
--- a/src/test/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerializationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/starlarkdebug/server/DebuggerSerializationTest.java
@@ -25,7 +25,6 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.starlarkdebugging.StarlarkDebuggingProtos.Value;
import com.google.devtools.build.lib.syntax.Depset;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkValue;
@@ -264,7 +263,7 @@
}
private static void assertTypeAndDescription(Object object, Value value) {
- assertThat(value.getType()).isEqualTo(EvalUtils.getDataTypeName(object));
+ assertThat(value.getType()).isEqualTo(Starlark.type(object));
assertThat(value.getDescription()).isEqualTo(Starlark.repr(object));
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
index a07414c..f2f5355 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvalUtilsTest.java
@@ -52,14 +52,14 @@
@Test
public void testDataTypeNames() throws Exception {
- assertThat(EvalUtils.getDataTypeName("foo")).isEqualTo("string");
- assertThat(EvalUtils.getDataTypeName(3)).isEqualTo("int");
- assertThat(EvalUtils.getDataTypeName(Tuple.of(1, 2, 3))).isEqualTo("tuple");
- assertThat(EvalUtils.getDataTypeName(makeList(null))).isEqualTo("list");
- assertThat(EvalUtils.getDataTypeName(makeDict(null))).isEqualTo("dict");
- assertThat(EvalUtils.getDataTypeName(Starlark.NONE)).isEqualTo("NoneType");
- assertThat(EvalUtils.getDataTypeName(new MockClassA())).isEqualTo("MockClassA");
- assertThat(EvalUtils.getDataTypeName(new MockClassB())).isEqualTo("MockClassA");
+ assertThat(Starlark.type("foo")).isEqualTo("string");
+ assertThat(Starlark.type(3)).isEqualTo("int");
+ assertThat(Starlark.type(Tuple.of(1, 2, 3))).isEqualTo("tuple");
+ assertThat(Starlark.type(makeList(null))).isEqualTo("list");
+ assertThat(Starlark.type(makeDict(null))).isEqualTo("dict");
+ assertThat(Starlark.type(Starlark.NONE)).isEqualTo("NoneType");
+ assertThat(Starlark.type(new MockClassA())).isEqualTo("MockClassA");
+ assertThat(Starlark.type(new MockClassB())).isEqualTo("MockClassA");
}
@Test