changeset 2647:f4df97bf5392

8059921: Missing compile error in Java 8 mode for Interface.super.field access Reviewed-by: mcimadamore, jlahoda
author vromero
date Mon, 24 Nov 2014 14:55:38 -0800
parents edb89e5d7ace
children 9e80ab1dad9e
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out
diffstat 3 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 20 11:27:57 2014 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Nov 24 14:55:38 2014 -0800
@@ -3243,6 +3243,10 @@
         // Determine the symbol represented by the selection.
         env.info.pendingResolutionPhase = null;
         Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
+        if (sym.kind == VAR && sym.name != names._super && env.info.defaultSuperCallSite != null) {
+            log.error(tree.selected.pos(), "not.encl.class", site.tsym);
+            sym = syms.errSymbol;
+        }
         if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) {
             site = capture(site);
             sym = selectSym(tree, sitesym, site, env, resultInfo);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java	Mon Nov 24 14:55:38 2014 -0800
@@ -0,0 +1,31 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8059921
+ * @summary Missing compile error in Java 8 mode for Interface.super.field access
+ * @compile/fail/ref=ForbidAccessToFieldUsingSuperTest.out -XDrawDiagnostics ForbidAccessToFieldUsingSuperTest.java
+ */
+
+public class ForbidAccessToFieldUsingSuperTest {
+    class C {
+        int m() { return 0; }
+    }
+
+    interface T {
+        int f = 0;
+        C c = null;
+        default int mm() {
+            return 0;
+        }
+    }
+
+    interface T1 extends T {}
+
+    class X implements T1 {
+        int i = T1.super.f;        //fail
+        int j = T1.super.c.m();    //fail
+
+        void foo(Runnable r) {
+            foo(T1.super::mm);     //should'n fail
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out	Mon Nov 24 14:55:38 2014 -0800
@@ -0,0 +1,3 @@
+ForbidAccessToFieldUsingSuperTest.java:24:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
+ForbidAccessToFieldUsingSuperTest.java:25:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
+2 errors