提交 a9da4e07 编写于 作者: M mcimadamore

8006749: compiler does not allow Object protected methods to be used in lambda

Summary: Check.checkFunctionalInterface should take into account 'fake' override
Reviewed-by: jjg
上级 752aa228
......@@ -356,26 +356,11 @@ public class Types {
}
public Type getType(Type site) {
if (capture(site) != site) {
Type formalInterface = site.tsym.type;
ListBuffer<Type> typeargs = ListBuffer.lb();
List<Type> actualTypeargs = site.getTypeArguments();
//simply replace the wildcards with its bound
for (Type t : formalInterface.getTypeArguments()) {
if (actualTypeargs.head.hasTag(WILDCARD)) {
WildcardType wt = (WildcardType)actualTypeargs.head;
typeargs.append(wt.type);
} else {
typeargs.append(actualTypeargs.head);
}
actualTypeargs = actualTypeargs.tail;
}
site = subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
if (!chk.checkValidGenericType(site)) {
//if the inferred functional interface type is not well-formed,
//or if it's not a subtype of the original target, issue an error
throw failure(diags.fragment("no.suitable.functional.intf.inst", site));
}
site = removeWildcards(site);
if (!chk.checkValidGenericType(site)) {
//if the inferred functional interface type is not well-formed,
//or if it's not a subtype of the original target, issue an error
throw failure(diags.fragment("no.suitable.functional.intf.inst", site));
}
return memberType(site, descSym);
}
......@@ -584,6 +569,27 @@ public class Types {
return false;
}
}
public Type removeWildcards(Type site) {
if (capture(site) != site) {
Type formalInterface = site.tsym.type;
ListBuffer<Type> typeargs = ListBuffer.lb();
List<Type> actualTypeargs = site.getTypeArguments();
//simply replace the wildcards with its bound
for (Type t : formalInterface.getTypeArguments()) {
if (actualTypeargs.head.hasTag(WILDCARD)) {
WildcardType wt = (WildcardType)actualTypeargs.head;
typeargs.append(wt.type);
} else {
typeargs.append(actualTypeargs.head);
}
actualTypeargs = actualTypeargs.tail;
}
return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
} else {
return site;
}
}
// </editor-fold>
/**
......
......@@ -2232,10 +2232,13 @@ public class Check {
void checkFunctionalInterface(JCTree tree, Type funcInterface) {
ClassType c = new ClassType(Type.noType, List.<Type>nil(), null);
ClassSymbol csym = new ClassSymbol(0, names.empty, c, syms.noSymbol);
c.interfaces_field = List.of(funcInterface);
c.interfaces_field = List.of(types.removeWildcards(funcInterface));
c.supertype_field = syms.objectType;
c.tsym = csym;
csym.members_field = new Scope(csym);
Symbol descSym = types.findDescriptorSymbol(funcInterface.tsym);
Type descType = types.findDescriptorType(funcInterface);
csym.members_field.enter(new MethodSymbol(PUBLIC, descSym.name, descType, csym));
csym.completer = null;
checkImplementations(tree, csym, csym);
}
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8006749
* @summary compiler does not allow Object protected methods to be used in lambda
* @compile LambdaConv26.java
*/
public class LambdaConv26 {
interface I {
Object clone();
}
Object m() { return null; }
void test() {
I i1 = ()->null;
I i2 = this::m;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册