aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemanticsOptions.java8
2 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
index 70c4c95943..cde876e58a 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/FunctionDefStatement.java
@@ -49,12 +49,21 @@ public class FunctionDefStatement extends Statement {
defaultValues.add(expr.eval(env));
}
}
+
+ FunctionSignature sig = signature.getSignature();
+ if (env.getSemantics().incompatibleKeywordOnlySyntax
+ && sig.getShape().getMandatoryNamedOnly() > 0) {
+ throw new EvalException(
+ getLocation(),
+ "Keyword-only argument is forbidden. You can temporarily disable this "
+ + "error using the flag --incompatible_keyword_only_syntax=false");
+ }
+
env.update(
ident.getName(),
new UserDefinedFunction(
ident,
- FunctionSignature.WithValues.<Object, SkylarkType>create(
- signature.getSignature(), defaultValues, types),
+ FunctionSignature.WithValues.<Object, SkylarkType>create(sig, defaultValues, types),
statements,
env.getGlobals()));
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemanticsOptions.java
index 5ed2643e90..0c83c25760 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemanticsOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemanticsOptions.java
@@ -50,4 +50,12 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable
help = "If set to true, disables the deprecated `set` constructor for depsets."
)
public boolean incompatibleDepsetConstructor;
+
+ @Option(
+ name = "incompatible_keyword_only_syntax",
+ defaultValue = "false",
+ category = "incompatible changes",
+ help = "If set to true, disables the keyword-only argument syntax in function definition."
+ )
+ public boolean incompatibleKeywordOnlySyntax;
}