test/tools/javac/8015701/AnonymousParameters.java

Fri, 05 Jul 2013 11:04:22 +0100

author
mcimadamore
date
Fri, 05 Jul 2013 11:04:22 +0100
changeset 1890
bfbedbfc522a
parent 1808
8717586f7b05
permissions
-rw-r--r--

8016702: use of ternary operator in lambda expression gives incorrect results
Summary: Constant types erroneously creep in during inference
Reviewed-by: jjg, vromero

emc@1808 1 /*
emc@1808 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
emc@1808 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
emc@1808 4 *
emc@1808 5 * This code is free software; you can redistribute it and/or modify it
emc@1808 6 * under the terms of the GNU General Public License version 2 only, as
emc@1808 7 * published by the Free Software Foundation.
emc@1808 8 *
emc@1808 9 * This code is distributed in the hope that it will be useful, but WITHOUT
emc@1808 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
emc@1808 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
emc@1808 12 * version 2 for more details (a copy is included in the LICENSE file that
emc@1808 13 * accompanied this code).
emc@1808 14 *
emc@1808 15 * You should have received a copy of the GNU General Public License version
emc@1808 16 * 2 along with this work; if not, write to the Free Software Foundation,
emc@1808 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
emc@1808 18 *
emc@1808 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
emc@1808 20 * or visit www.oracle.com if you need additional information or have any
emc@1808 21 * questions.
emc@1808 22 */
emc@1808 23
emc@1808 24 /*
emc@1808 25 * @test
emc@1808 26 * @bug 8015701
emc@1808 27 * @summary javac should generate method parameters correctly.
emc@1808 28 * @compile -parameters AnonymousParameters.java
emc@1808 29 * @run main AnonymousParameters
emc@1808 30 */
emc@1808 31 import java.lang.Class;
emc@1808 32 import java.lang.reflect.Constructor;
emc@1808 33 import java.lang.reflect.Parameter;
emc@1808 34 import java.util.concurrent.Callable;
emc@1808 35
emc@1808 36 public class AnonymousParameters {
emc@1808 37
emc@1808 38 String[] names = {
emc@1808 39 "this$0",
emc@1808 40 "val$message"
emc@1808 41 };
emc@1808 42
emc@1808 43 public static void main(String... args) throws Exception {
emc@1808 44 new AnonymousParameters().run();
emc@1808 45 }
emc@1808 46
emc@1808 47 void run() throws Exception {
emc@1808 48 Class<?> cls = new ParameterNames().makeInner("hello").getClass();
emc@1808 49 Constructor<?> ctor = cls.getDeclaredConstructors()[0];
emc@1808 50 Parameter[] params = ctor.getParameters();
emc@1808 51
emc@1808 52 if(params.length == 2) {
emc@1808 53 for(int i = 0; i < 2; i++) {
emc@1808 54 System.err.println("Testing parameter " + params[i].getName());
emc@1808 55 if(!params[i].getName().equals(names[i]))
emc@1808 56 error("Expected parameter name " + names[i] +
emc@1808 57 " got " + params[i].getName());
emc@1808 58 }
emc@1808 59 } else
emc@1808 60 error("Expected 2 parameters");
emc@1808 61
emc@1808 62 if(0 != errors)
emc@1808 63 throw new Exception("MethodParameters test failed with " +
emc@1808 64 errors + " errors");
emc@1808 65 }
emc@1808 66
emc@1808 67 void error(String msg) {
emc@1808 68 System.err.println("Error: " + msg);
emc@1808 69 errors++;
emc@1808 70 }
emc@1808 71
emc@1808 72 int errors;
emc@1808 73 }
emc@1808 74
emc@1808 75 class ParameterNames {
emc@1808 76
emc@1808 77 public Callable<String> makeInner(final String message) {
emc@1808 78 return new Callable<String>() {
emc@1808 79 public String call() throws Exception {
emc@1808 80 return message;
emc@1808 81 }
emc@1808 82 };
emc@1808 83 }
emc@1808 84
emc@1808 85 public static void main(String... args) throws Exception {
emc@1808 86 ParameterNames test = new ParameterNames();
emc@1808 87 System.out.println(test.makeInner("Hello").call());
emc@1808 88 }
emc@1808 89 }

mercurial