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

Reviewed-by: mcimadamore, jlahoda
This commit is contained in:
Vicente Romero 2014-11-20 09:43:13 -08:00
parent a2b0a2413e
commit 418c9789d6
3 changed files with 38 additions and 0 deletions

View File

@ -3233,6 +3233,10 @@ public class Attr extends JCTree.Visitor {
// 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().contains(KindSelector.TYP_PCK)) {
site = capture(site);
sym = selectSym(tree, sitesym, site, env, resultInfo);

View File

@ -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
}
}
}

View File

@ -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