From 31a1bf1ff7a7b2c216249a53fb5415f18dd94e46 Mon Sep 17 00:00:00 2001 From: cushon Date: Wed, 21 Nov 2018 12:38:59 -0800 Subject: Fix error reporting for import resolution errors on nested types MOE_MIGRATED_REVID=222446808 --- .../com/google/turbine/binder/lookup/ImportIndex.java | 10 +++++++--- .../google/turbine/binder/lookup/LookupResult.java | 4 +++- .../com/google/turbine/binder/BinderErrorTest.java | 19 ++++++++++++++++++- 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 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); } -- cgit v1.2.3