diff options
author | sadayapalam <none@none> | 2018-05-08 12:10:09 +0100 |
---|---|---|
committer | Raluca Sauciuc <ralucas@google.com> | 2018-05-14 14:37:31 -0700 |
commit | cebd569be996cabc46b0795f9f401237f2562665 (patch) | |
tree | d59286204e56e5ec9f16d820118f401f3a2aa601 | |
parent | fe8ba49ea8854950d9d756b7b2ac937c4a3f9577 (diff) | |
download | jdk8u_langtools-cebd569be996cabc46b0795f9f401237f2562665.tar.gz |
8142476: Call site initialization exception
8142476: Call site initialization exception caused by LambdaConversionException: Invalid receiver type
Summary: Incorrect handling of intersection typed receiver in method references results in call site initialization exception
Reviewed-by: mcimadamore
cherry-pick of dc69f044b from openjdk9
Change-Id: I4397e545877051153d8f891cd0f2a3157953df53
-rw-r--r-- | src/share/classes/com/sun/tools/javac/comp/TransTypes.java | 10 | ||||
-rw-r--r-- | test/tools/javac/lambda/methodReference/IntersectionTypeReceiverTest2.java | 51 |
2 files changed, 60 insertions, 1 deletions
diff --git a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java index 84118f1f..51c42f7e 100644 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -31,6 +31,7 @@ import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; +import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; @@ -874,7 +875,14 @@ public class TransTypes extends TreeTranslator { } public void visitReference(JCMemberReference tree) { - tree.expr = translate(tree.expr, erasure(tree.expr.type)); + Type t = types.skipTypeVars(tree.expr.type, false); + Type receiverTarget = t.isCompound() ? erasure(tree.sym.owner.type) : erasure(t); + if (tree.kind == ReferenceKind.UNBOUND) { + tree.expr = make.Type(receiverTarget); + } else { + tree.expr = translate(tree.expr, receiverTarget); + } + tree.type = erasure(tree.type); if (tree.varargsElement != null) tree.varargsElement = erasure(tree.varargsElement); diff --git a/test/tools/javac/lambda/methodReference/IntersectionTypeReceiverTest2.java b/test/tools/javac/lambda/methodReference/IntersectionTypeReceiverTest2.java new file mode 100644 index 00000000..e02763b5 --- /dev/null +++ b/test/tools/javac/lambda/methodReference/IntersectionTypeReceiverTest2.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, 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 8142476 + * @summary Test that Call site initialization exception is not thrown when the method + reference receiver is of intersection type. + * @run main IntersectionTypeReceiverTest2 + */ + +public class IntersectionTypeReceiverTest2 { + interface I { + } + + interface J { + void foo(); + } + + static <T extends I & J> void bar(T t) { + Runnable r = t::foo; + } + + public static void main(String[] args) { + class A implements I, J { + public void foo() { + } + } + bar(new A()); + } +}
\ No newline at end of file |