changeset 2185:6e30a513c945

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
author mcimadamore
date Thu, 06 Jun 2013 15:30:14 +0100
parents 79fd9cfa55f2
children 7889d1fe2597
files src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/6360970/T6360970.java test/tools/javac/6360970/T6360970.out
diffstat 3 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Jun 05 16:58:10 2013 +0400
+++ b/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/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/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