8059921: Missing compile error in Java 8 mode for Interface.super.field access

Mon, 24 Nov 2014 14:55:38 -0800

author
vromero
date
Mon, 24 Nov 2014 14:55:38 -0800
changeset 2610
f4df97bf5392
parent 2609
edb89e5d7ace
child 2611
9e80ab1dad9e

8059921: Missing compile error in Java 8 mode for Interface.super.field access
Reviewed-by: mcimadamore, jlahoda

src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java file | annotate | diff | comparison | revisions
test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Nov 20 11:27:57 2014 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Nov 24 14:55:38 2014 -0800
     1.3 @@ -3243,6 +3243,10 @@
     1.4          // Determine the symbol represented by the selection.
     1.5          env.info.pendingResolutionPhase = null;
     1.6          Symbol sym = selectSym(tree, sitesym, site, env, resultInfo);
     1.7 +        if (sym.kind == VAR && sym.name != names._super && env.info.defaultSuperCallSite != null) {
     1.8 +            log.error(tree.selected.pos(), "not.encl.class", site.tsym);
     1.9 +            sym = syms.errSymbol;
    1.10 +        }
    1.11          if (sym.exists() && !isType(sym) && (pkind() & (PCK | TYP)) != 0) {
    1.12              site = capture(site);
    1.13              sym = selectSym(tree, sitesym, site, env, resultInfo);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.java	Mon Nov 24 14:55:38 2014 -0800
     2.3 @@ -0,0 +1,31 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug 8059921
     2.7 + * @summary Missing compile error in Java 8 mode for Interface.super.field access
     2.8 + * @compile/fail/ref=ForbidAccessToFieldUsingSuperTest.out -XDrawDiagnostics ForbidAccessToFieldUsingSuperTest.java
     2.9 + */
    2.10 +
    2.11 +public class ForbidAccessToFieldUsingSuperTest {
    2.12 +    class C {
    2.13 +        int m() { return 0; }
    2.14 +    }
    2.15 +
    2.16 +    interface T {
    2.17 +        int f = 0;
    2.18 +        C c = null;
    2.19 +        default int mm() {
    2.20 +            return 0;
    2.21 +        }
    2.22 +    }
    2.23 +
    2.24 +    interface T1 extends T {}
    2.25 +
    2.26 +    class X implements T1 {
    2.27 +        int i = T1.super.f;        //fail
    2.28 +        int j = T1.super.c.m();    //fail
    2.29 +
    2.30 +        void foo(Runnable r) {
    2.31 +            foo(T1.super::mm);     //should'n fail
    2.32 +        }
    2.33 +    }
    2.34 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/T8059921/ForbidAccessToFieldUsingSuperTest.out	Mon Nov 24 14:55:38 2014 -0800
     3.3 @@ -0,0 +1,3 @@
     3.4 +ForbidAccessToFieldUsingSuperTest.java:24:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
     3.5 +ForbidAccessToFieldUsingSuperTest.java:25:19: compiler.err.not.encl.class: ForbidAccessToFieldUsingSuperTest.T1
     3.6 +2 errors

mercurial