Thu, 28 Feb 2013 14:05:44 +0000
8008813: Structural most specific fails when method reference is passed to overloaded method
Summary: Bad logic for checking most specific method reference type
Reviewed-by: jjg
src/share/classes/com/sun/tools/javac/comp/Resolve.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/MostSpecific08.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 28 14:00:52 2013 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 28 14:05:44 2013 +0000 1.3 @@ -984,7 +984,7 @@ 1.4 Type ret_t = desc_t.getReturnType(); 1.5 Type ret_s = desc_s.getReturnType(); 1.6 result &= ((tree.refPolyKind == PolyKind.STANDALONE) 1.7 - ? standaloneMostSpecific(ret_t, ret_s, tree.type, warn) 1.8 + ? standaloneMostSpecific(ret_t, ret_s, tree.sym.type.getReturnType(), warn) 1.9 : polyMostSpecific(ret_t, ret_s, warn)); 1.10 } else { 1.11 return;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/lambda/MostSpecific08.java Thu Feb 28 14:05:44 2013 +0000 2.3 @@ -0,0 +1,62 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8008813 2.30 + * @summary Structural most specific fails when method reference is passed to overloaded method 2.31 + * @compile MostSpecific08.java 2.32 + */ 2.33 +class MostSpecific08 { 2.34 + 2.35 + static class C { 2.36 + int getInt() { return -1; } 2.37 + Integer getInteger() { return -1; } 2.38 + } 2.39 + 2.40 + interface IntResult { } 2.41 + interface ReferenceResult<X> { } 2.42 + 2.43 + interface PrimitiveFunction { 2.44 + int f(C c); 2.45 + } 2.46 + 2.47 + interface ReferenceFunction<X> { 2.48 + X f(C c); 2.49 + } 2.50 + 2.51 + interface Tester { 2.52 + IntResult apply(PrimitiveFunction p); 2.53 + <Z> ReferenceResult<Z> apply(ReferenceFunction<Z> p); 2.54 + } 2.55 + 2.56 + void testMref(Tester t) { 2.57 + IntResult pr = t.apply(C::getInt); 2.58 + ReferenceResult<Integer> rr = t.apply(C::getInteger); 2.59 + } 2.60 + 2.61 + void testLambda(Tester t) { 2.62 + IntResult pr = t.apply(c->c.getInt()); 2.63 + ReferenceResult<Integer> rr = t.apply(c->c.getInteger()); 2.64 + } 2.65 +}