langtools/test/tools/javac/lambda/LambdaParenGenericOrig.java
author rfield
Sun, 22 Dec 2013 21:57:01 -0800
changeset 22168 a48fe7ec473d
permissions -rw-r--r--
8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses Summary: properly type convert the body of a lambda expression (forward port to JDK9 of 8029558) Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22168
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     1
/*
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     4
 *
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     8
 *
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    13
 * accompanied this code).
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    14
 *
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    18
 *
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    21
 * questions.
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    22
 */
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    23
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    24
/*
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    25
 * @test
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    26
 * @bug 8029558
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    27
 * @summary VerifyError lambda body is parenthesized generic value (originally submitted test)
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    28
 * @author  Dmitrii Afanasyev
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    29
 * @run main LambdaParenGenericOrig
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    30
 */
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    31
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    32
public class LambdaParenGenericOrig {
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    33
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    34
    @FunctionalInterface
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    35
    public static interface Function1<R, A> {
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    36
        R apply(A input);
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    37
    }
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    38
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    39
    @FunctionalInterface
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    40
    public static interface Function2<R, A1, A2> {
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    41
        R apply(A1 input1, A2 input2);
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    42
    }
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    43
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    44
    public static void main(String[] args) {
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    45
        final Function2<Integer, Integer, Integer> add = (x, y) -> x + y;
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    46
        final Function1<Integer, Integer> inc = x -> (add.apply(x, 1));
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    47
        System.out.println(inc.apply(0));
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    48
    }
a48fe7ec473d 8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
diff changeset
    49
}