diff options
author | cushon <cushon@google.com> | 2019-01-25 16:58:23 -0800 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2019-01-28 21:35:37 -0800 |
commit | bf9349300bed8d29daf8eb80d3766d88fa41d316 (patch) | |
tree | 75ebdadb30614c11de848830d154f3e373e00fe6 | |
parent | c612ef98e6c5bf5eef7859289a52cf9f5711f62c (diff) | |
download | turbine-bf9349300bed8d29daf8eb80d3766d88fa41d316.tar.gz |
Fix error reporting for resolution failures on nested annotations
MOE_MIGRATED_REVID=230994917
-rw-r--r-- | java/com/google/turbine/binder/ConstEvaluator.java | 8 | ||||
-rw-r--r-- | javatests/com/google/turbine/binder/BinderErrorTest.java | 38 |
2 files changed, 44 insertions, 2 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java index cfc63fc..0e837a4 100644 --- a/java/com/google/turbine/binder/ConstEvaluator.java +++ b/java/com/google/turbine/binder/ConstEvaluator.java @@ -18,6 +18,7 @@ package com.google.turbine.binder; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; @@ -953,9 +954,16 @@ public strictfp class ConstEvaluator { private AnnotationValue evalAnno(Tree.Anno t) { LookupResult result = scope.lookup(new LookupKey(t.name())); + if (result == null) { + throw error( + t.name().get(0).position(), ErrorKind.CANNOT_RESOLVE, Joiner.on(".").join(t.name())); + } ClassSymbol sym = (ClassSymbol) result.sym(); for (Ident name : result.remaining()) { sym = Resolve.resolve(env, sym, sym, name); + if (sym == null) { + throw error(name.position(), ErrorKind.CANNOT_RESOLVE, name.value()); + } } if (sym == null) { return null; diff --git a/javatests/com/google/turbine/binder/BinderErrorTest.java b/javatests/com/google/turbine/binder/BinderErrorTest.java index de2237d..5a4d97e 100644 --- a/javatests/com/google/turbine/binder/BinderErrorTest.java +++ b/javatests/com/google/turbine/binder/BinderErrorTest.java @@ -514,9 +514,9 @@ public class BinderErrorTest { "}", }, { - "<>:4: error: could not evaluate constant expression", + "<>:4: error: could not resolve RUNTIME", "@Retention(@RetentionPolicy.RUNTIME)", - " ^", + " ^", }, }, { @@ -535,6 +535,40 @@ public class BinderErrorTest { " ^", }, }, + { + { + "class One {", + " @interface A {", // + " B[] b();", + " }", + " @interface B {}", + "}", + "@One.A(b = {@B})", + "class T {}", + }, + { + "<>:7: error: could not resolve B", // + "@One.A(b = {@B})", + " ^", + }, + }, + { + { + "class One {", + " @interface A {", // + " B[] b();", + " }", + " @interface B {}", + "}", + "@One.A(b = {@One.NoSuch})", + "class T {}", + }, + { + "<>:7: error: could not resolve NoSuch", // + "@One.A(b = {@One.NoSuch})", + " ^", + }, + } }; return Arrays.asList((Object[][]) testCases); } |