OpenJDK / amber / amber
changeset 16293:bf5e87940aee
8007285: AbstractMethodError instead of compile-time error when method reference with super and abstract
Summary: Missing abstractness check on super rmethod references
Reviewed-by: jjg
author | mcimadamore |
---|---|
date | Fri, 15 Feb 2013 16:28:57 +0000 |
parents | 3be2cdacb3b3 |
children | 0c291a3cd60d |
files | langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java langtools/test/tools/javac/lambda/MethodReference62.java langtools/test/tools/javac/lambda/MethodReference62.out |
diffstat | 3 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Feb 15 16:28:07 2013 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Feb 15 16:28:57 2013 +0000 @@ -2622,8 +2622,11 @@ } } + 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 @@ 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) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/MethodReference62.java Fri Feb 15 16:28:57 2013 +0000 @@ -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; + } + } +}