mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8369517: Compilation mismatch for equivalent lambda and method reference
Reviewed-by: mcimadamore
This commit is contained in:
parent
1f1f7bb448
commit
e5a272a590
@ -277,6 +277,7 @@ public enum Source {
|
||||
JAVA_BASE_TRANSITIVE(JDK25, Fragments.FeatureJavaBaseTransitive, DiagKind.PLURAL),
|
||||
PRIVATE_MEMBERS_IN_PERMITS_CLAUSE(JDK19),
|
||||
ERASE_POLY_SIG_RETURN_TYPE(JDK24),
|
||||
CAPTURE_MREF_RETURN_TYPE(JDK26),
|
||||
;
|
||||
|
||||
enum DiagKind {
|
||||
|
||||
@ -124,6 +124,7 @@ public class Attr extends JCTree.Visitor {
|
||||
final ArgumentAttr argumentAttr;
|
||||
final MatchBindingsComputer matchBindingsComputer;
|
||||
final AttrRecover attrRecover;
|
||||
final boolean captureMRefReturnType;
|
||||
|
||||
public static Attr instance(Context context) {
|
||||
Attr instance = context.get(attrKey);
|
||||
@ -175,6 +176,7 @@ public class Attr extends JCTree.Visitor {
|
||||
Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF.allowedInSource(source);
|
||||
sourceName = source.name;
|
||||
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning");
|
||||
captureMRefReturnType = Source.Feature.ERASE_POLY_SIG_RETURN_TYPE.allowedInSource(source);
|
||||
|
||||
statInfo = new ResultInfo(KindSelector.NIL, Type.noType);
|
||||
varAssignmentInfo = new ResultInfo(KindSelector.ASG, Type.noType);
|
||||
@ -3832,9 +3834,10 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
if (!returnType.hasTag(VOID) && !resType.hasTag(VOID)) {
|
||||
Type capturedResType = captureMRefReturnType ? types.capture(resType) : resType;
|
||||
if (resType.isErroneous() ||
|
||||
new FunctionalReturnContext(checkContext).compatible(resType, returnType,
|
||||
checkContext.checkWarner(tree, resType, returnType))) {
|
||||
new FunctionalReturnContext(checkContext).compatible(capturedResType, returnType,
|
||||
checkContext.checkWarner(tree, capturedResType, returnType))) {
|
||||
incompatibleReturnType = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2025, 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 8369517
|
||||
* @summary Compilation mismatch for equivalent lambda and method reference
|
||||
* @compile/fail/ref=ResultTypeNotBeingCapturedTest.out -XDrawDiagnostics ResultTypeNotBeingCapturedTest.java
|
||||
*/
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class ResultTypeNotBeingCapturedTest {
|
||||
interface X<T> {
|
||||
X<T> self();
|
||||
}
|
||||
|
||||
static X<?> makeX() {return null;}
|
||||
|
||||
static <R> X<R> create(Supplier<? extends R> supplier) {return null;}
|
||||
|
||||
static X<X<?>> methodRef() {
|
||||
return create(ResultTypeNotBeingCapturedTest::makeX).self();
|
||||
}
|
||||
|
||||
static X<X<?>> lambda() {
|
||||
return create(() -> makeX()).self();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
ResultTypeNotBeingCapturedTest.java:43:66: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ResultTypeNotBeingCapturedTest.X<ResultTypeNotBeingCapturedTest.X<compiler.misc.type.captureof: 1, ?>>, ResultTypeNotBeingCapturedTest.X<ResultTypeNotBeingCapturedTest.X<?>>)
|
||||
ResultTypeNotBeingCapturedTest.java:47:42: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ResultTypeNotBeingCapturedTest.X<ResultTypeNotBeingCapturedTest.X<compiler.misc.type.captureof: 1, ?>>, ResultTypeNotBeingCapturedTest.X<ResultTypeNotBeingCapturedTest.X<?>>)
|
||||
2 errors
|
||||
Loading…
x
Reference in New Issue
Block a user