6360970: javac erroneously accept ambiguous field reference
Summary: clash between ambiguous fields in superinterface and unambiguous field in subinterface is erroneously marked as unambiguous
Reviewed-by: jjg, vromero
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jun 05 16:58:10 2013 +0400
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Jun 06 15:30:14 2013 +0100
@@ -1207,7 +1207,7 @@
bestSoFar.kind != AMBIGUOUS && l.nonEmpty();
l = l.tail) {
sym = findField(env, site, name, l.head.tsym);
- if (bestSoFar.kind < AMBIGUOUS && sym.kind < AMBIGUOUS &&
+ if (bestSoFar.exists() && sym.exists() &&
sym.owner != bestSoFar.owner)
bestSoFar = new AmbiguityError(bestSoFar, sym);
else if (sym.kind < bestSoFar.kind)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/6360970/T6360970.java Thu Jun 06 15:30:14 2013 +0100
@@ -0,0 +1,25 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 6360970
+ * @summary javac erroneously accept ambiguous field reference
+ * @compile/fail/ref=T6360970.out -XDrawDiagnostics T6360970.java
+ */
+class T6360970 {
+ interface A {
+ int i = 1;
+ }
+
+ interface B {
+ int i = 2;
+ }
+
+ interface C extends A, B { }
+
+ static class D {
+ public static final int i = 0;
+ }
+
+ static class E extends D implements C { }
+
+ int i = E.i; //ambiguous
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/6360970/T6360970.out Thu Jun 06 15:30:14 2013 +0100
@@ -0,0 +1,2 @@
+T6360970.java:24:14: compiler.err.ref.ambiguous: i, kindname.variable, i, T6360970.D, kindname.variable, i, T6360970.A
+1 error