aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorLiam Miller-Cushon <cushon@google.com>2021-07-20 12:38:40 -0700
committerJavac Team <javac-team+copybara@google.com>2021-07-20 12:39:26 -0700
commitbe693b07c4beaa19d48d311d53dda023f40a71b5 (patch)
treefd0cbcb001b6dfde5df8bd65a86fe44f4db46033 /java
parent08d22a6682829f7a4da2bfca7775fdd8b5ff000b (diff)
downloadturbine-be693b07c4beaa19d48d311d53dda023f40a71b5.tar.gz
Report an error for annotation element values without a name
outside of single-element annotations, i.e. `@A(42)` is OK but `@A(42, false)` is not. Also fix the AST position for boolean literals. PiperOrigin-RevId: 385847809
Diffstat (limited to 'java')
-rw-r--r--java/com/google/turbine/binder/ConstEvaluator.java3
-rw-r--r--java/com/google/turbine/diag/TurbineError.java1
-rw-r--r--java/com/google/turbine/parse/ConstExpressionParser.java18
3 files changed, 16 insertions, 6 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java
index 78d6905..486b865 100644
--- a/java/com/google/turbine/binder/ConstEvaluator.java
+++ b/java/com/google/turbine/binder/ConstEvaluator.java
@@ -946,6 +946,9 @@ public strictfp class ConstEvaluator {
key = assign.name().value();
expr = assign.expr();
} else {
+ if (info.args().size() != 1) {
+ throw error(arg.position(), ErrorKind.ANNOTATION_VALUE_NAME);
+ }
// expand the implicit 'value' name; `@Foo(42)` is sugar for `@Foo(value=42)`
key = "value";
expr = arg;
diff --git a/java/com/google/turbine/diag/TurbineError.java b/java/com/google/turbine/diag/TurbineError.java
index f3ebf08..e3f8a0e 100644
--- a/java/com/google/turbine/diag/TurbineError.java
+++ b/java/com/google/turbine/diag/TurbineError.java
@@ -50,6 +50,7 @@ public class TurbineError extends Error {
OPERAND_TYPE("bad operand type %s"),
CYCLIC_HIERARCHY("cycle in class hierarchy: %s"),
NOT_AN_ANNOTATION("%s is not an annotation"),
+ ANNOTATION_VALUE_NAME("expected an annotation value of the form name=value"),
NONREPEATABLE_ANNOTATION("%s is not @Repeatable"),
DUPLICATE_DECLARATION("duplicate declaration of %s"),
BAD_MODULE_INFO("unexpected declaration found in module-info"),
diff --git a/java/com/google/turbine/parse/ConstExpressionParser.java b/java/com/google/turbine/parse/ConstExpressionParser.java
index f0ce692..372cf9d 100644
--- a/java/com/google/turbine/parse/ConstExpressionParser.java
+++ b/java/com/google/turbine/parse/ConstExpressionParser.java
@@ -107,13 +107,19 @@ public class ConstExpressionParser {
case FLOAT_LITERAL:
return finishLiteral(TurbineConstantTypeKind.FLOAT, negate);
case TRUE:
- eat();
- return new Tree.Literal(
- position, TurbineConstantTypeKind.BOOLEAN, new Const.BooleanValue(true));
+ {
+ int pos = position;
+ eat();
+ return new Tree.Literal(
+ pos, TurbineConstantTypeKind.BOOLEAN, new Const.BooleanValue(true));
+ }
case FALSE:
- eat();
- return new Tree.Literal(
- position, TurbineConstantTypeKind.BOOLEAN, new Const.BooleanValue(false));
+ {
+ int pos = position;
+ eat();
+ return new Tree.Literal(
+ pos, TurbineConstantTypeKind.BOOLEAN, new Const.BooleanValue(false));
+ }
case CHAR_LITERAL:
return finishLiteral(TurbineConstantTypeKind.CHAR, negate);
case STRING_LITERAL: