diff options
author | dslomov <dslomov@google.com> | 2017-09-22 12:44:18 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-09-22 13:40:28 +0200 |
commit | 5d41dbea25c6c9e3776516c7aa3598b8c153a410 (patch) | |
tree | 4f8f05b25a4a1737463334bff14c7b16355acb71 | |
parent | 7b091c1397a82258e26ab5336df6c8dae1d97384 (diff) |
Automated rollback of commit 17214ac78ffaec369d5d5bafe62a39730473cfaa.
*** Reason for rollback ***
Rolled back commit enforces stricter parameter checks. Will fix and roll forward
This creates several failures on the nightly build of Bazel:
ERROR: /home/ci/workspace/Global/rules_closure-node=linux-x86_64/closure/protobuf/test/BUILD:23:1: no such package '@com_google_protobuf_protoc//': Cannot convert parameter 'url' to type string or sequence of strings, in method download_and_extract(List, string, string, string, string) of 'repository_ctx' and referenced by '//closure/protobuf/test:example_proto_gen'.
ERROR: Analysis of target '//closure/protobuf/test:example_lib' failed; build aborted: no such package '@com_google_protobuf_protoc//': Cannot convert parameter 'url' to type string or sequence of strings, in method download_and_extract(List, string, string, string, string) of 'repository_ctx'.
*** Original change description ***
Check parameter types for methods when multiple types are allowed.
Fixes #3714
RELNOTES: None.
PiperOrigin-RevId: 169669802
3 files changed, 8 insertions, 72 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java index fbb4ef11ce..f3019e471a 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/FuncallExpression.java @@ -25,7 +25,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.skylarkinterface.Param; -import com.google.devtools.build.lib.skylarkinterface.ParamType; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; @@ -389,23 +388,11 @@ public final class FuncallExpression extends Expression { } private static SkylarkType getType(Param param) { - if (param.allowedTypes().length > 0) { - Preconditions.checkState(Object.class.equals(param.type())); - SkylarkType result = SkylarkType.BOTTOM; - for (ParamType paramType : param.allowedTypes()) { - SkylarkType t = paramType.generic1() != Object.class - ? SkylarkType.of(paramType.type(), paramType.generic1()) - : SkylarkType.of(paramType.type()); - result = SkylarkType.Union.of(result, t); - } - return result; - } else { - SkylarkType type = - param.generic1() != Object.class - ? SkylarkType.of(param.type(), param.generic1()) - : SkylarkType.of(param.type()); - return type; - } + SkylarkType type = + param.generic1() != Object.class + ? SkylarkType.of(param.type(), param.generic1()) + : SkylarkType.of(param.type()); + return type; } /** diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java index c4f5f5af30..f3371cc13a 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java @@ -298,8 +298,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { public void testCreateSpawnActionArgumentsBadExecutable() throws Exception { checkErrorContains( createRuleContext("//foo:foo"), - "Cannot convert parameter 'executable' to type File or string, in method " - + "run(list inputs, list outputs, list arguments, int executable) of 'actions'", + "expected file or string for executable but got int instead", "ruleContext.actions.run(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", @@ -625,7 +624,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase { SkylarkRuleContext ruleContext = createRuleContext("//foo:foo"); checkErrorContains( ruleContext, - "Cannot convert parameter 'content' to type string or Args", + "Unexpected type: Integer", "ruleContext.actions.write(", " output = ruleContext.files.srcs[0],", " content = 1,", 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 175aedad67..1febef33f9 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 @@ -28,7 +28,6 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.skylarkinterface.Param; -import com.google.devtools.build.lib.skylarkinterface.ParamType; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature; @@ -156,18 +155,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { positional = false, named = true ), - @Param( - name = "multi", - allowedTypes = { - @ParamType(type = String.class), - @ParamType(type = Integer.class), - @ParamType(type = SkylarkList.class, generic1 = Integer.class), - }, - defaultValue = "None", - noneable = true, - positional = false, - named = true - ) } ) public String withParams( @@ -177,8 +164,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { boolean named, boolean optionalNamed, Object nonNoneable, - Object noneable, - Object multi) { + Object noneable) { return "with_params(" + pos1 + ", " @@ -191,8 +177,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { + optionalNamed + ", " + nonNoneable.toString() - + (noneable != Runtime.NONE ? ", " + noneable : "") - + (multi != Runtime.NONE ? ", " + multi : "") + ")"; } @@ -760,21 +744,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { .testLookup("b", "with_params(1, true, false, true, false, a)"); new SkylarkTest() .update("mock", new Mock()) - .setUp("b = mock.with_params(1, True, named=True, multi=1)") - .testLookup("b", "with_params(1, true, false, true, false, a, 1)"); - new SkylarkTest() - .update("mock", new Mock()) - .setUp("b = mock.with_params(1, True, named=True, multi='abc')") - .testLookup("b", "with_params(1, true, false, true, false, a, abc)"); - - new SkylarkTest() - .update("mock", new Mock()) - .setUp("b = mock.with_params(1, True, named=True, multi=[1,2,3])") - .testLookup("b", "with_params(1, true, false, true, false, a, [1, 2, 3])"); - - - new SkylarkTest() - .update("mock", new Mock()) .setUp("") .testIfExactError( "parameter 'named' has no default value, in method with_params(int, bool) of 'Mock'", @@ -812,25 +781,6 @@ public class SkylarkEvaluationTest extends EvaluationTest { "parameter 'nonNoneable' cannot be None, in method with_params(int, bool, bool, " + "bool named, bool optionalNamed, NoneType nonNoneable) of 'Mock'", "mock.with_params(1, True, True, named=True, optionalNamed=False, nonNoneable=None)"); - - new SkylarkTest() - .update("mock", new Mock()) - .setUp("") - .testIfExactError( - "Cannot convert parameter 'multi' to type string or int or sequence of ints or" - + " NoneType, in method with_params(int, bool, bool named, bool multi) of 'Mock'", - "mock.with_params(1, True, named=True, multi=False)" - ); - - // We do not enforce list item parameter type constraints. - // Test for this behavior. - new SkylarkTest() - .update("mock", new Mock()) - .setUp("b = mock.with_params(1, True, named=True, multi=['a', 'b'])") - .testLookup( - "b", "with_params(1, true, false, true, false, a, [\"a\", \"b\"])" - ); - } @Test |