mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8030855: Default methods should be visible under source previous to 8
Reviewed-by: jjg, dlsmith
This commit is contained in:
parent
cf7f5c0b61
commit
edee080e4a
3 changed files with 41 additions and 33 deletions
|
@ -207,9 +207,6 @@ public enum Source {
|
||||||
public boolean allowDefaultMethods() {
|
public boolean allowDefaultMethods() {
|
||||||
return compareTo(JDK1_8) >= 0;
|
return compareTo(JDK1_8) >= 0;
|
||||||
}
|
}
|
||||||
public boolean allowDefaultMethodsResolution() {
|
|
||||||
return compareTo(JDK1_7) >= 0;
|
|
||||||
}
|
|
||||||
public boolean allowStaticInterfaceMethods() {
|
public boolean allowStaticInterfaceMethods() {
|
||||||
return compareTo(JDK1_8) >= 0;
|
return compareTo(JDK1_8) >= 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,10 +91,9 @@ public class Resolve {
|
||||||
TreeInfo treeinfo;
|
TreeInfo treeinfo;
|
||||||
Types types;
|
Types types;
|
||||||
JCDiagnostic.Factory diags;
|
JCDiagnostic.Factory diags;
|
||||||
public final boolean boxingEnabled; // = source.allowBoxing();
|
public final boolean boxingEnabled;
|
||||||
public final boolean varargsEnabled; // = source.allowVarargs();
|
public final boolean varargsEnabled;
|
||||||
public final boolean allowMethodHandles;
|
public final boolean allowMethodHandles;
|
||||||
public final boolean allowDefaultMethodsResolution;
|
|
||||||
public final boolean allowStructuralMostSpecific;
|
public final boolean allowStructuralMostSpecific;
|
||||||
private final boolean debugResolve;
|
private final boolean debugResolve;
|
||||||
private final boolean compactMethodDiags;
|
private final boolean compactMethodDiags;
|
||||||
|
@ -136,7 +135,6 @@ public class Resolve {
|
||||||
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
|
verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options);
|
||||||
Target target = Target.instance(context);
|
Target target = Target.instance(context);
|
||||||
allowMethodHandles = target.hasMethodHandles();
|
allowMethodHandles = target.hasMethodHandles();
|
||||||
allowDefaultMethodsResolution = source.allowDefaultMethodsResolution();
|
|
||||||
allowStructuralMostSpecific = source.allowStructuralMostSpecific();
|
allowStructuralMostSpecific = source.allowStructuralMostSpecific();
|
||||||
polymorphicSignatureScope = new Scope(syms.noSymbol);
|
polymorphicSignatureScope = new Scope(syms.noSymbol);
|
||||||
|
|
||||||
|
@ -1680,7 +1678,6 @@ public class Resolve {
|
||||||
bestSoFar : methodNotFound;
|
bestSoFar : methodNotFound;
|
||||||
|
|
||||||
for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
|
for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
|
||||||
if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethodsResolution) break;
|
|
||||||
//keep searching for abstract methods
|
//keep searching for abstract methods
|
||||||
for (Type itype : itypes[iphase2.ordinal()]) {
|
for (Type itype : itypes[iphase2.ordinal()]) {
|
||||||
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
|
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
|
||||||
|
@ -1713,10 +1710,8 @@ public class Resolve {
|
||||||
//from superinterfaces)
|
//from superinterfaces)
|
||||||
if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) {
|
if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) {
|
||||||
return this;
|
return this;
|
||||||
} else if (rs.allowDefaultMethodsResolution) {
|
|
||||||
return DEFAULT_OK;
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return DEFAULT_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3340,9 +3335,9 @@ public class Resolve {
|
||||||
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
|
if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true;
|
||||||
env1 = env1.outer;
|
env1 = env1.outer;
|
||||||
}
|
}
|
||||||
if (allowDefaultMethodsResolution && c.isInterface() &&
|
if (c.isInterface() &&
|
||||||
name == names._super && !isStatic(env) &&
|
name == names._super && !isStatic(env) &&
|
||||||
types.isDirectSuperInterface(c, env.enclClass.sym)) {
|
types.isDirectSuperInterface(c, env.enclClass.sym)) {
|
||||||
//this might be a default super call if one of the superinterfaces is 'c'
|
//this might be a default super call if one of the superinterfaces is 'c'
|
||||||
for (Type t : pruneInterfaces(env.enclClass.type)) {
|
for (Type t : pruneInterfaces(env.enclClass.type)) {
|
||||||
if (t.tsym == c) {
|
if (t.tsym == c) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,20 +23,21 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8029240
|
* @bug 8029240 8030855
|
||||||
* @summary Default methods not always visible under -source 7
|
* @summary Default methods not always visible under -source 7
|
||||||
|
* Default methods should be visible under source previous to 8
|
||||||
* @library /tools/javac/lib
|
* @library /tools/javac/lib
|
||||||
* @build ToolBox
|
* @build ToolBox
|
||||||
* @run main DefaultMethodsNotVisibileForSource7Test
|
* @run main DefaultMethodsNotVisibleForSourceLessThan8Test
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class DefaultMethodsNotVisibileForSource7Test {
|
public class DefaultMethodsNotVisibleForSourceLessThan8Test {
|
||||||
// common definitions
|
// 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 =
|
static final String ISrc =
|
||||||
"interface I {\n" +
|
"interface I {\n" +
|
||||||
" default void m() {}\n" +
|
" default void m() {}\n" +
|
||||||
|
@ -54,22 +55,22 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
// test legacy implementations
|
// test legacy implementations
|
||||||
static final String C1Src =
|
static final String C1Src =
|
||||||
"class C1 implements I {\n" +
|
"class C1 implements I {\n" +
|
||||||
" @Override public void m() {}\n" +
|
" public void m() {}\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
static final String C2Src =
|
static final String C2Src =
|
||||||
"class C2 implements J {\n" +
|
"class C2 implements J {\n" +
|
||||||
" @Override public void m() {}\n" +
|
" public void m() {}\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
static final String C3Src =
|
static final String C3Src =
|
||||||
"class C3 extends A {\n" +
|
"class C3 extends A {\n" +
|
||||||
" @Override public void m() {}\n" +
|
" public void m() {}\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
static final String C4Src =
|
static final String C4Src =
|
||||||
"class C4 extends B {\n" +
|
"class C4 extends B {\n" +
|
||||||
" @Override public void m() {}\n" +
|
" public void m() {}\n" +
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
//test legacy invocations
|
//test legacy invocations
|
||||||
|
@ -99,10 +100,25 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
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();
|
testsPreparation();
|
||||||
testLegacyImplementations();
|
testLegacyImplementations();
|
||||||
testLegacyInvocations();
|
testLegacyInvocations();
|
||||||
|
@ -110,27 +126,27 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
void testsPreparation() throws Exception {
|
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
|
/* as an extra check let's make sure that interface 'I' can't be compiled
|
||||||
* with source 7
|
* with source < 8
|
||||||
*/
|
*/
|
||||||
ToolBox.JavaToolArgs javacArgs =
|
ToolBox.JavaToolArgs javacArgs =
|
||||||
new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
|
new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL)
|
||||||
.setOptions("-d", "out", "-source", "7")
|
.setOptions("-d", outDir, "-source", source)
|
||||||
.setSources(ISrc);
|
.setSources(ISrc);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
|
|
||||||
//but it should compile with source >= 8
|
//but it should compile with source >= 8
|
||||||
javacArgs =
|
javacArgs =
|
||||||
new ToolBox.JavaToolArgs()
|
new ToolBox.JavaToolArgs()
|
||||||
.setOptions("-d", "out")
|
.setOptions("-d", outDir)
|
||||||
.setSources(ISrc);
|
.setSources(ISrc);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
|
|
||||||
javacArgs =
|
javacArgs =
|
||||||
new ToolBox.JavaToolArgs()
|
new ToolBox.JavaToolArgs()
|
||||||
.setOptions("-cp", "out", "-d", "out", "-source", "7")
|
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
|
||||||
.setSources(JSrc, ASrc, BSrc);
|
.setSources(JSrc, ASrc, BSrc);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +155,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
//compile C1-4
|
//compile C1-4
|
||||||
ToolBox.JavaToolArgs javacArgs =
|
ToolBox.JavaToolArgs javacArgs =
|
||||||
new ToolBox.JavaToolArgs()
|
new ToolBox.JavaToolArgs()
|
||||||
.setOptions("-cp", "out", "-d", "out", "-source", "7")
|
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
|
||||||
.setSources(C1Src, C2Src, C3Src, C4Src);
|
.setSources(C1Src, C2Src, C3Src, C4Src);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +164,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
//compile LegacyInvocation
|
//compile LegacyInvocation
|
||||||
ToolBox.JavaToolArgs javacArgs =
|
ToolBox.JavaToolArgs javacArgs =
|
||||||
new ToolBox.JavaToolArgs()
|
new ToolBox.JavaToolArgs()
|
||||||
.setOptions("-cp", "out", "-d", "out", "-source", "7")
|
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
|
||||||
.setSources(LegacyInvocationSrc);
|
.setSources(LegacyInvocationSrc);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +173,7 @@ public class DefaultMethodsNotVisibileForSource7Test {
|
||||||
//compile SubA, SubB
|
//compile SubA, SubB
|
||||||
ToolBox.JavaToolArgs javacArgs =
|
ToolBox.JavaToolArgs javacArgs =
|
||||||
new ToolBox.JavaToolArgs()
|
new ToolBox.JavaToolArgs()
|
||||||
.setOptions("-cp", "out", "-d", "out", "-source", "7")
|
.setOptions("-cp", outDir, "-d", outDir, "-source", source)
|
||||||
.setSources(SubASrc, SubBSrc);
|
.setSources(SubASrc, SubBSrc);
|
||||||
ToolBox.javac(javacArgs);
|
ToolBox.javac(javacArgs);
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue