diff options
-rw-r--r-- | java/com/google/turbine/binder/ConstEvaluator.java | 3 | ||||
-rw-r--r-- | javatests/com/google/turbine/binder/BinderErrorTest.java | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java index 134a567..0598d8e 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 { throw error(tree.position(), ErrorKind.EXPRESSION_ERROR); } Const value = eval(tree); + if (value == null) { + throw error(tree.position(), ErrorKind.EXPRESSION_ERROR); + } switch (ty.tyKind()) { case PRIM_TY: return coerce((Const.Value) value, ((Type.PrimTy) ty).primkind()); diff --git a/javatests/com/google/turbine/binder/BinderErrorTest.java b/javatests/com/google/turbine/binder/BinderErrorTest.java index 4c5abbd..aaac42d 100644 --- a/javatests/com/google/turbine/binder/BinderErrorTest.java +++ b/javatests/com/google/turbine/binder/BinderErrorTest.java @@ -294,6 +294,36 @@ public class BinderErrorTest { " ^", }, }, + { + { + "public class Test {", // + " @interface Anno {", + " int[] value() default 0;", + " }", + " @Anno(value=Test.NO_SUCH) int x;", + "}", + }, + { + "<>:5: error: could not evaluate constant expression", // + " @Anno(value=Test.NO_SUCH) int x;", + " ^", + }, + }, + { + { + "public class Test {", // + " @interface Anno {", + " String value() default \"\";", + " }", + " @Anno(value=null) int x;", + "}", + }, + { + "<>:5: error: invalid annotation argument", // + " @Anno(value=null) int x;", + " ^", + }, + }, }; return Arrays.asList((Object[][]) testCases); } |