提交 bb5d828b 编写于 作者: V vromero

8030855: Default methods should be visible under source previous to 8

Reviewed-by: jjg, dlsmith
上级 889ba5f3
......@@ -203,9 +203,6 @@ public enum Source {
public boolean allowDefaultMethods() {
return compareTo(JDK1_8) >= 0;
}
public boolean allowDefaultMethodsResolution() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowStaticInterfaceMethods() {
return compareTo(JDK1_8) >= 0;
}
......
......@@ -92,10 +92,9 @@ public class Resolve {
TreeInfo treeinfo;
Types types;
JCDiagnostic.Factory diags;
public final boolean boxingEnabled; // = source.allowBoxing();
public final boolean varargsEnabled; // = source.allowVarargs();
public final boolean boxingEnabled;
public final boolean varargsEnabled;
public final boolean allowMethodHandles;
public final boolean allowDefaultMethodsResolution;
public final boolean allowStructuralMostSpecific;
private final boolean debugResolve;
private final boolean compactMethodDiags;
......@@ -137,7 +136,6 @@ public class Resolve {
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
Target target = Target.instance(context);
allowMethodHandles = target.hasMethodHandles();
allowDefaultMethodsResolution = source.allowDefaultMethodsResolution();
allowStructuralMostSpecific = source.allowStructuralMostSpecific();
polymorphicSignatureScope = new Scope(syms.noSymbol);
......@@ -1681,7 +1679,6 @@ public class Resolve {
bestSoFar : methodNotFound;
for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethodsResolution) break;
//keep searching for abstract methods
for (Type itype : itypes[iphase2.ordinal()]) {
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
......@@ -1714,10 +1711,8 @@ public class Resolve {
//from superinterfaces)
if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) {
return this;
} else if (rs.allowDefaultMethodsResolution) {
return DEFAULT_OK;
} else {
return null;
return DEFAULT_OK;
}
}
},
......@@ -3341,9 +3336,9 @@ public class Resolve {
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
env1 = env1.outer;
}
if (allowDefaultMethodsResolution && c.isInterface() &&
name == names._super && !isStatic(env) &&
types.isDirectSuperInterface(c, env.enclClass.sym)) {
if (c.isInterface() &&
name == names._super && !isStatic(env) &&
types.isDirectSuperInterface(c, env.enclClass.sym)) {
//this might be a default super call if one of the superinterfaces is 'c'
for (Type t : pruneInterfaces(env.enclClass.type)) {
if (t.tsym == c) {
......
......@@ -23,20 +23,21 @@
/*
* @test
* @bug 8029240
* @bug 8029240 8030855
* @summary Default methods not always visible under -source 7
* Default methods should be visible under source previous to 8
* @library /tools/javac/lib
* @build ToolBox
* @run main DefaultMethodsNotVisibileForSource7Test
* @run main DefaultMethodsNotVisibleForSourceLessThan8Test
*/
import java.nio.file.Files;
import java.nio.file.Paths;
public class DefaultMethodsNotVisibileForSource7Test {
public class DefaultMethodsNotVisibleForSourceLessThan8Test {
// common definitions
// this one should be compiled with source 8, the rest with source 7
// this one should be compiled with source 8, the rest with source < 8
static final String ISrc =
"interface I {\n" +
" default void m() {}\n" +
......@@ -54,22 +55,22 @@ public class DefaultMethodsNotVisibileForSource7Test {
// test legacy implementations
static final String C1Src =
"class C1 implements I {\n" +
" @Override public void m() {}\n" +
" public void m() {}\n" +
"}";
static final String C2Src =
"class C2 implements J {\n" +
" @Override public void m() {}\n" +
" public void m() {}\n" +
"}";
static final String C3Src =
"class C3 extends A {\n" +
" @Override public void m() {}\n" +
" public void m() {}\n" +
"}";
static final String C4Src =
"class C4 extends B {\n" +
" @Override public void m() {}\n" +
" public void m() {}\n" +
"}";
//test legacy invocations
......@@ -99,10 +100,25 @@ public class DefaultMethodsNotVisibileForSource7Test {
"}";
public static void main(String[] args) throws Exception {
new DefaultMethodsNotVisibileForSource7Test().run();
String[] sources = new String[] {
"1.2",
"1.3",
"1.4",
"1.5",
"1.6",
"1.7",
};
for (String source : sources) {
new DefaultMethodsNotVisibleForSourceLessThan8Test().run(source);
}
}
void run() throws Exception {
String outDir;
String source;
void run(String source) throws Exception {
this.source = source;
outDir = "out" + source.replace('.', '_');
testsPreparation();
testLegacyImplementations();
testLegacyInvocations();
......@@ -110,27 +126,27 @@ public class DefaultMethodsNotVisibileForSource7Test {
}
void testsPreparation() throws Exception {
Files.createDirectory(Paths.get("out"));
Files.createDirectory(Paths.get(outDir));
/* as an extra check let's make sure that interface 'I' can't be compiled
* with source 7
* with source < 8
*/
ToolBox.JavaToolArgs javacArgs =
new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
.setOptions("-d", "out", "-source", "7")
.setOptions("-d", outDir, "-source", source)
.setSources(ISrc);
ToolBox.javac(javacArgs);
//but it should compile with source >= 8
javacArgs =
new ToolBox.JavaToolArgs()
.setOptions("-d", "out")
.setOptions("-d", outDir)
.setSources(ISrc);
ToolBox.javac(javacArgs);
javacArgs =
new ToolBox.JavaToolArgs()
.setOptions("-cp", "out", "-d", "out", "-source", "7")
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
.setSources(JSrc, ASrc, BSrc);
ToolBox.javac(javacArgs);
}
......@@ -139,7 +155,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
//compile C1-4
ToolBox.JavaToolArgs javacArgs =
new ToolBox.JavaToolArgs()
.setOptions("-cp", "out", "-d", "out", "-source", "7")
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
.setSources(C1Src, C2Src, C3Src, C4Src);
ToolBox.javac(javacArgs);
}
......@@ -148,7 +164,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
//compile LegacyInvocation
ToolBox.JavaToolArgs javacArgs =
new ToolBox.JavaToolArgs()
.setOptions("-cp", "out", "-d", "out", "-source", "7")
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
.setSources(LegacyInvocationSrc);
ToolBox.javac(javacArgs);
}
......@@ -157,7 +173,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
//compile SubA, SubB
ToolBox.JavaToolArgs javacArgs =
new ToolBox.JavaToolArgs()
.setOptions("-cp", "out", "-d", "out", "-source", "7")
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
.setSources(SubASrc, SubBSrc);
ToolBox.javac(javacArgs);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册