diff options
author | cushon <cushon@google.com> | 2017-03-10 17:47:05 -0800 |
---|---|---|
committer | Liam Miller-Cushon <cushon@google.com> | 2017-03-18 00:23:33 -0700 |
commit | 466e61c082af2d622db5549eff8ab9f338cd6435 (patch) | |
tree | 886b281bbbc78184bba9137d9e402b1aeb60fc83 | |
parent | e186fd9f6b51ccb177d1e250507c5452abe1eb9c (diff) | |
download | turbine-466e61c082af2d622db5549eff8ab9f338cd6435.tar.gz |
Fix an import resolution bug
The order of the classpath and source scopes was transposed when
resolving symbols in imports. Sources should be searched first, and then
the bootclasspath, and then the regular classpath. This prevent
compilations from succeeding if the same symbol appeared on the
classpath and in source, and an import could only be resolved using the
version in source.
MOE_MIGRATED_REVID=149818281
3 files changed, 17 insertions, 1 deletions
diff --git a/java/com/google/turbine/binder/Binder.java b/java/com/google/turbine/binder/Binder.java index ccb3ed5..121c96e 100644 --- a/java/com/google/turbine/binder/Binder.java +++ b/java/com/google/turbine/binder/Binder.java @@ -231,7 +231,7 @@ public class Binder { Scope packageScope = tli.lookupPackage(packagename); CanonicalSymbolResolver importResolver = new CanonicalResolver( - packagename, CompoundEnv.<ClassSymbol, BoundClass>of(ienv).append(classPathEnv)); + packagename, CompoundEnv.<ClassSymbol, BoundClass>of(classPathEnv).append(ienv)); ImportScope importScope = ImportIndex.create(importResolver, tli, unit.imports()); ImportScope wildImportScope = WildImportIndex.create(importResolver, tli, unit.imports()); MemberImportIndex memberImports = new MemberImportIndex(importResolver, tli, unit.imports()); diff --git a/javatests/com/google/turbine/lower/LowerIntegrationTest.java b/javatests/com/google/turbine/lower/LowerIntegrationTest.java index aeb15b4..7cb2dfa 100644 --- a/javatests/com/google/turbine/lower/LowerIntegrationTest.java +++ b/javatests/com/google/turbine/lower/LowerIntegrationTest.java @@ -294,6 +294,7 @@ public class LowerIntegrationTest { "B8148131.test", "B8056066.test", "B8056066b.test", + "source_bootclasspath_order.test", }; List<Object[]> tests = ImmutableList.copyOf(testCases).stream().map(x -> new Object[] {x}).collect(toList()); diff --git a/javatests/com/google/turbine/lower/testdata/source_bootclasspath_order.test b/javatests/com/google/turbine/lower/testdata/source_bootclasspath_order.test new file mode 100644 index 0000000..3c20e62 --- /dev/null +++ b/javatests/com/google/turbine/lower/testdata/source_bootclasspath_order.test @@ -0,0 +1,15 @@ +=== Test.java === +import java.lang.String.I; +class Test { + void f(I s) { + s.foo(); + } +} + +=== java/lang/String.java === +package java.lang; +public class String { + public static class I { + public void foo() {} + } +}
\ No newline at end of file |