Fri, 10 Dec 2010 15:24:17 +0000
6199075: Unambiguous varargs method calls flagged as ambiguous
Summary: javac does not implement overload resolution w.r.t. varargs methods as described in the JLS
Reviewed-by: jjg
mcimadamore@674 | 1 | /* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@674 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@674 | 3 | * |
mcimadamore@674 | 4 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@674 | 5 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@674 | 6 | * published by the Free Software Foundation. |
mcimadamore@674 | 7 | * |
mcimadamore@674 | 8 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@674 | 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@674 | 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@674 | 11 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@674 | 12 | * accompanied this code). |
mcimadamore@674 | 13 | * |
mcimadamore@674 | 14 | * You should have received a copy of the GNU General Public License version |
mcimadamore@674 | 15 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@674 | 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@674 | 17 | * |
mcimadamore@674 | 18 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@674 | 19 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@674 | 20 | * questions. |
mcimadamore@674 | 21 | */ |
mcimadamore@674 | 22 | |
mcimadamore@674 | 23 | /* |
mcimadamore@674 | 24 | * @test |
mcimadamore@674 | 25 | * @bug 6754038 6979327 |
mcimadamore@674 | 26 | * @summary Generate call sites for method handle |
mcimadamore@674 | 27 | * @author jrose |
mcimadamore@674 | 28 | * |
mcimadamore@674 | 29 | * @compile/fail/ref=InvokeMHTrans.out -Werror -XDrawDiagnostics -source 7 -target 7 InvokeMHTrans.java |
mcimadamore@674 | 30 | */ |
mcimadamore@674 | 31 | |
mcimadamore@674 | 32 | /* |
mcimadamore@674 | 33 | * Standalone testing: |
mcimadamore@674 | 34 | * <code> |
mcimadamore@674 | 35 | * $ cd $MY_REPO_DIR/langtools |
mcimadamore@674 | 36 | * $ (cd make; make) |
mcimadamore@674 | 37 | * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/meth/InvokeMH.java |
mcimadamore@674 | 38 | * $ javap -c -classpath dist meth.InvokeMH |
mcimadamore@674 | 39 | * </code> |
mcimadamore@674 | 40 | */ |
mcimadamore@674 | 41 | |
mcimadamore@674 | 42 | package meth; |
mcimadamore@674 | 43 | |
mcimadamore@674 | 44 | import java.dyn.MethodHandle; |
mcimadamore@674 | 45 | |
mcimadamore@674 | 46 | public class InvokeMHTrans { |
mcimadamore@674 | 47 | void test(MethodHandle mh_SiO, |
mcimadamore@674 | 48 | MethodHandle mh_vS, |
mcimadamore@674 | 49 | MethodHandle mh_vi, |
mcimadamore@674 | 50 | MethodHandle mh_vv) throws Throwable { |
mcimadamore@674 | 51 | Object o; String s; int i; // for return type testing |
mcimadamore@674 | 52 | |
mcimadamore@674 | 53 | // next five must have sig = (String,int)Object |
mcimadamore@674 | 54 | mh_SiO.invokeExact("world", 123); |
mcimadamore@674 | 55 | mh_SiO.invokeExact("mundus", 456); |
mcimadamore@674 | 56 | Object k = "kosmos"; |
mcimadamore@674 | 57 | mh_SiO.invokeExact((String)k, 789); |
mcimadamore@674 | 58 | o = mh_SiO.invokeExact((String)null, 000); |
mcimadamore@674 | 59 | o = mh_SiO.<Object>invokeExact("arda", -123); |
mcimadamore@674 | 60 | |
mcimadamore@674 | 61 | // sig = ()String |
mcimadamore@674 | 62 | s = mh_vS.<String>invokeExact(); |
mcimadamore@674 | 63 | |
mcimadamore@674 | 64 | // sig = ()int |
mcimadamore@674 | 65 | i = mh_vi.<int>invokeExact(); |
mcimadamore@674 | 66 | o = mh_vi.<int>invokeExact(); |
mcimadamore@674 | 67 | //s = mh_vi.<int>invokeExact(); //BAD |
mcimadamore@674 | 68 | mh_vi.<int>invokeExact(); |
mcimadamore@674 | 69 | |
mcimadamore@674 | 70 | // sig = ()void |
mcimadamore@674 | 71 | //o = mh_vv.<void>invokeExact(); //BAD |
mcimadamore@674 | 72 | mh_vv.<void>invokeExact(); |
mcimadamore@674 | 73 | } |
mcimadamore@674 | 74 | |
mcimadamore@674 | 75 | void testGen(MethodHandle mh_SiO, |
mcimadamore@674 | 76 | MethodHandle mh_vS, |
mcimadamore@674 | 77 | MethodHandle mh_vi, |
mcimadamore@674 | 78 | MethodHandle mh_vv) throws Throwable { |
mcimadamore@674 | 79 | Object o; String s; int i; // for return type testing |
mcimadamore@674 | 80 | |
mcimadamore@674 | 81 | // next five must have sig = (*,*)* |
mcimadamore@674 | 82 | mh_SiO.invokeGeneric((Object)"world", (Object)123); |
mcimadamore@674 | 83 | mh_SiO.<void>invokeGeneric((Object)"mundus", (Object)456); |
mcimadamore@674 | 84 | Object k = "kosmos"; |
mcimadamore@674 | 85 | mh_SiO.invokeGeneric(k, 789); |
mcimadamore@674 | 86 | o = mh_SiO.invokeGeneric(null, 000); |
mcimadamore@674 | 87 | o = mh_SiO.<Object>invokeGeneric("arda", -123); |
mcimadamore@674 | 88 | |
mcimadamore@674 | 89 | // sig = ()String |
mcimadamore@674 | 90 | o = mh_vS.invokeGeneric(); |
mcimadamore@674 | 91 | |
mcimadamore@674 | 92 | // sig = ()int |
mcimadamore@674 | 93 | i = mh_vi.<int>invokeGeneric(); |
mcimadamore@674 | 94 | o = mh_vi.invokeGeneric(); |
mcimadamore@674 | 95 | //s = mh_vi.<int>invokeGeneric(); //BAD |
mcimadamore@674 | 96 | mh_vi.<void>invokeGeneric(); |
mcimadamore@674 | 97 | |
mcimadamore@674 | 98 | // sig = ()void |
mcimadamore@674 | 99 | //o = mh_vv.<void>invokeGeneric(); //BAD |
mcimadamore@674 | 100 | o = mh_vv.invokeGeneric(); |
mcimadamore@674 | 101 | } |
mcimadamore@674 | 102 | } |