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:
Maurizio Cimadamore 2013-02-15 16:28:57 +00:00
parent f8f9896cc7
commit e88e06a5e0
3 changed files with 35 additions and 3 deletions

View File

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

View 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;
}
}
}

View File

@ -0,0 +1,2 @@
MethodReference62.java:19:21: compiler.err.abstract.cant.be.accessed.directly: kindname.method, foo(), MethodReference62.Sup
1 error