Create useSkylarkSemantics for @SkylarkCallable, so annotated methods can specifically get a semantics object
This is slightly redundant with useEnvironment, yes (as one can easily obtain the semantics object with Environment), but we intend on restricting useEnvironment so that structField=true methods cannot specify useEnvironment, but *can* specify useSkylarkSemantics.
In general, we can also ween off non structField methods to use useSkylarkSemantics instead of useEnvironment in cases where this is feasible.
RELNOTES: None.
PiperOrigin-RevId: 190082547
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 d49d0d5..4a1a09d 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
@@ -244,16 +244,19 @@
doc = "",
useLocation = true,
useAst = true,
- useEnvironment = true
+ useEnvironment = true,
+ useSkylarkSemantics = true
)
public String withExtraInterpreterParams(
- Location location, FuncallExpression func, Environment env) {
+ Location location, FuncallExpression func, Environment env, SkylarkSemantics sem) {
return "with_extra("
+ location.getStartLine()
+ ", "
+ func.getArguments().size()
+ ", "
+ env.isGlobal()
+ + ", "
+ + (sem != null)
+ ")";
}
@@ -308,7 +311,8 @@
},
useAst = true,
useLocation = true,
- useEnvironment = true
+ useEnvironment = true,
+ useSkylarkSemantics = true
)
public String withParamsAndExtraInterpreterParams(
Integer pos1,
@@ -321,7 +325,8 @@
Object multi,
Location location,
FuncallExpression func,
- Environment env) {
+ Environment env,
+ SkylarkSemantics sem) {
return "with_params_and_extra("
+ pos1
+ ", "
@@ -342,6 +347,8 @@
+ func.getArguments().size()
+ ", "
+ env.isGlobal()
+ + ", "
+ + (sem != null)
+ ")";
}
@@ -1034,7 +1041,7 @@
new SkylarkTest()
.update("mock", new Mock())
.setUp("v = mock.with_extra()")
- .testLookup("v", "with_extra(1, 0, true)");
+ .testLookup("v", "with_extra(1, 0, true, true)");
}
@Test
@@ -1042,7 +1049,7 @@
new SkylarkTest()
.update("mock", new Mock())
.setUp("b = mock.with_params_and_extra(1, True, named=True)")
- .testLookup("b", "with_params_and_extra(1, true, false, true, false, a, 1, 3, true)");
+ .testLookup("b", "with_params_and_extra(1, true, false, true, false, a, 1, 3, true, true)");
}
@Test