mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-25 15:20:11 +00:00
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
Missing abstractness check on super rmethod references Reviewed-by: jjg
This commit is contained in:
parent
f8f9896cc7
commit
e88e06a5e0
@ -2622,8 +2622,11 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
that.sym = refSym.baseSymbol();
|
||||
that.kind = lookupHelper.referenceKind(that.sym);
|
||||
|
||||
if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) {
|
||||
if (refSym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
if (that.sym.isStatic() && TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
exprType.getTypeArguments().nonEmpty()) {
|
||||
//static ref with class type-args
|
||||
log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
|
||||
@ -2632,14 +2635,19 @@ public class Attr extends JCTree.Visitor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (refSym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
!lookupHelper.referenceKind(refSym).isUnbound()) {
|
||||
if (that.sym.isStatic() && !TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
!that.kind.isUnbound()) {
|
||||
//no static bound mrefs
|
||||
log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()),
|
||||
diags.fragment("static.bound.mref"));
|
||||
result = that.type = types.createErrorType(target);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!refSym.isStatic() && that.kind == JCMemberReference.ReferenceKind.SUPER) {
|
||||
// Check that super-qualified symbols are not abstract (JLS)
|
||||
rs.checkNonAbstract(that.pos(), that.sym);
|
||||
}
|
||||
}
|
||||
|
||||
if (desc.getReturnType() == Type.recoveryType) {
|
||||
|
||||
22
langtools/test/tools/javac/lambda/MethodReference62.java
Normal file
22
langtools/test/tools/javac/lambda/MethodReference62.java
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8007285
|
||||
* @summary AbstractMethodError instead of compile-time error when method reference with super and abstract
|
||||
* @compile/fail/ref=MethodReference62.out -XDrawDiagnostics MethodReference62.java
|
||||
*/
|
||||
class MethodReference62 {
|
||||
interface SAM {
|
||||
int m();
|
||||
}
|
||||
|
||||
static abstract class Sup {
|
||||
abstract int foo() ;
|
||||
}
|
||||
|
||||
static abstract class Sub extends Sup {
|
||||
abstract int foo() ;
|
||||
void test() {
|
||||
SAM s = super::foo;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
langtools/test/tools/javac/lambda/MethodReference62.out
Normal file
2
langtools/test/tools/javac/lambda/MethodReference62.out
Normal file
@ -0,0 +1,2 @@
|
||||
MethodReference62.java:19:21: compiler.err.abstract.cant.be.accessed.directly: kindname.method, foo(), MethodReference62.Sup
|
||||
1 error
|
||||
Loading…
x
Reference in New Issue
Block a user