aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-11-21 12:38:59 -0800
committerLiam Miller-Cushon <cushon@google.com>2019-01-28 21:35:22 -0800
commit31a1bf1ff7a7b2c216249a53fb5415f18dd94e46 (patch)
treeadff6e09eea1a668d1553e282cb7010486364823
parent090f9053177b517e2b52b79d4a9ff2aec214cc39 (diff)
downloadturbine-31a1bf1ff7a7b2c216249a53fb5415f18dd94e46.tar.gz
Fix error reporting for import resolution errors on nested types
MOE_MIGRATED_REVID=222446808
-rw-r--r--java/com/google/turbine/binder/lookup/ImportIndex.java10
-rw-r--r--java/com/google/turbine/binder/lookup/LookupResult.java4
-rw-r--r--javatests/com/google/turbine/binder/BinderErrorTest.java19
3 files changed, 28 insertions, 5 deletions
diff --git a/java/com/google/turbine/binder/lookup/ImportIndex.java b/java/com/google/turbine/binder/lookup/ImportIndex.java
index f28d905..97556ca 100644
--- a/java/com/google/turbine/binder/lookup/ImportIndex.java
+++ b/java/com/google/turbine/binder/lookup/ImportIndex.java
@@ -105,7 +105,10 @@ public class ImportIndex implements ImportScope {
}
ClassSymbol sym = (ClassSymbol) result.sym();
for (Tree.Ident bit : result.remaining()) {
- sym = resolveNext(log, i.position(), resolve, sym, bit);
+ sym = resolveNext(log, resolve, sym, bit);
+ if (sym == null) {
+ return null;
+ }
}
ClassSymbol resolved = sym;
return new ImportScope() {
@@ -118,14 +121,15 @@ public class ImportIndex implements ImportScope {
private static ClassSymbol resolveNext(
TurbineLogWithSource log,
- int position,
CanonicalSymbolResolver resolve,
ClassSymbol sym,
Ident bit) {
ClassSymbol next = resolve.resolveOne(sym, bit);
if (next == null) {
log.error(
- position, ErrorKind.SYMBOL_NOT_FOUND, new ClassSymbol(sym.binaryName() + '$' + bit));
+ bit.position(),
+ ErrorKind.SYMBOL_NOT_FOUND,
+ new ClassSymbol(sym.binaryName() + '$' + bit));
}
return next;
}
diff --git a/java/com/google/turbine/binder/lookup/LookupResult.java b/java/com/google/turbine/binder/lookup/LookupResult.java
index 7e0f737..8340386 100644
--- a/java/com/google/turbine/binder/lookup/LookupResult.java
+++ b/java/com/google/turbine/binder/lookup/LookupResult.java
@@ -16,6 +16,8 @@
package com.google.turbine.binder.lookup;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.Immutable;
import com.google.turbine.binder.sym.ClassSymbol;
@@ -45,7 +47,7 @@ public class LookupResult {
private final ImmutableList<Tree.Ident> remaining;
public LookupResult(Symbol sym, LookupKey remaining) {
- this.sym = sym;
+ this.sym = requireNonNull(sym);
this.remaining = remaining.hasNext() ? remaining.rest().simpleNames() : ImmutableList.of();
}
}
diff --git a/javatests/com/google/turbine/binder/BinderErrorTest.java b/javatests/com/google/turbine/binder/BinderErrorTest.java
index f6fb317..bc61e76 100644
--- a/javatests/com/google/turbine/binder/BinderErrorTest.java
+++ b/javatests/com/google/turbine/binder/BinderErrorTest.java
@@ -180,7 +180,7 @@ public class BinderErrorTest {
{
"<>:2: error: symbol not found java.util.List$NoSuch", //
"import java.util.List.NoSuch;",
- " ^",
+ " ^",
"<>:3: error: could not resolve NoSuch",
"public class Test extends NoSuch {",
" ^",
@@ -488,6 +488,23 @@ public class BinderErrorTest {
" ^",
},
},
+ {
+ {
+ "package p;", //
+ "import java.util.List.NoSuchAnno;",
+ "@NoSuchAnno",
+ "public class Test {",
+ "}",
+ },
+ {
+ "<>:2: error: symbol not found java.util.List$NoSuchAnno",
+ "import java.util.List.NoSuchAnno;",
+ " ^",
+ "<>:3: error: could not resolve NoSuchAnno",
+ "@NoSuchAnno",
+ " ^",
+ },
+ },
};
return Arrays.asList((Object[][]) testCases);
}