Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk17 Public archive

Commit

Permalink
8254571: Erroneous generic type inference in a lambda expression with…
Browse files Browse the repository at this point in the history
… a checked exception
  • Loading branch information
vicente-romero-oracle committed Jun 17, 2021
1 parent 7d7bdbe commit 343943b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ public void visitLambda(JCLambda tree) {
freeArgVars.nonEmpty()) {
stuckVars.addAll(freeArgVars);
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes()));
}
scanLambdaBody(tree, descType.getReturnType());
}
Expand All @@ -1238,6 +1239,7 @@ public void visitReference(JCMemberReference tree) {
tree.getOverloadKind() != JCMemberReference.OverloadKind.UNOVERLOADED) {
stuckVars.addAll(freeArgVars);
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
depVars.addAll(inferenceContext.freeVarsIn(descType.getThrownTypes()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021, 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 8254571
* @summary Erroneous generic type inference in a lambda expression with a checked exception
* @compile ConsiderExceptionTVarsInStuckExprs.java
*/

class ConsiderExceptionTVarsInStuckExprs {

public static void test() {
outer(nested(x -> mightThrow()));
}

static <A> void outer(Object o) {}

static <B, C, E extends Throwable> B nested(Fun<C,E> fun) {
return null;
}

interface Fun<X, Y extends Throwable> {
void m(X t) throws Y;
}

static void mightThrow() throws Exception {}
}

0 comments on commit 343943b

Please sign in to comment.