diff options
author | cushon <cushon@google.com> | 2017-09-28 17:07:42 -0700 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2017-09-29 17:09:51 -0700 |
commit | a5453051f0c8b71a833f6dc73caaea43bd24a0db (patch) | |
tree | 0993607a37bd87323e5ae4ea95a28d02bce42af5 | |
parent | f806b8f1c94e7ca6d3e91ba5125763529fdfdb0c (diff) | |
download | turbine-a5453051f0c8b71a833f6dc73caaea43bd24a0db.tar.gz |
Fix a crash in constant expression binding
MOE_MIGRATED_REVID=170420622
-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); } |