test/langtools/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     4
 *
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     8
 *
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    14
 *
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    18
 *
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    21
 * questions.
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    22
 */
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    23
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    24
/*
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    25
 * @test
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
    26
 * @bug 7030150 7039931
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    27
 * @summary Type inference for generic instance creation failed for formal type parameter
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    28
 * @modules jdk.compiler
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    29
 */
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    30
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    31
import com.sun.source.util.JavacTask;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    32
import java.net.URI;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    33
import java.util.Arrays;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    34
import javax.tools.Diagnostic;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    35
import javax.tools.JavaCompiler;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    36
import javax.tools.JavaFileObject;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    37
import javax.tools.SimpleJavaFileObject;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    38
import javax.tools.StandardJavaFileManager;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    39
import javax.tools.ToolProvider;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    40
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    41
public class GenericConstructorAndDiamondTest {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    42
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    43
    enum BoundKind {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    44
        NO_BOUND(""),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    45
        STRING_BOUND("extends String"),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    46
        INTEGER_BOUND("extends Integer");
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    47
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    48
        String boundStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    49
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    50
        private BoundKind(String boundStr) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    51
            this.boundStr = boundStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    52
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    53
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    54
        boolean matches(TypeArgumentKind tak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    55
            switch (tak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    56
                case NONE: return true;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    57
                case STRING: return this != INTEGER_BOUND;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    58
                case INTEGER: return this != STRING_BOUND;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    59
                default: return false;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    60
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    61
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    62
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    63
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    64
    enum ConstructorKind {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    65
        NON_GENERIC("Foo(Object o) {}"),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    66
        GENERIC_NO_BOUND("<T> Foo(T t) {}"),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    67
        GENERIC_STRING_BOUND("<T extends String> Foo(T t) {}"),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    68
        GENERIC_INTEGER_BOUND("<T extends Integer> Foo(T t) {}");
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    69
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    70
        String constrStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    71
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    72
        private ConstructorKind(String constrStr) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    73
            this.constrStr = constrStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    74
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    75
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    76
        boolean matches(ArgumentKind ak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    77
            switch (ak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    78
                case STRING: return this != GENERIC_INTEGER_BOUND;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    79
                case INTEGER: return this != GENERIC_STRING_BOUND;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    80
                default: return false;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    81
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    82
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    83
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    84
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    85
    enum TypeArgArity {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    86
        ONE(1),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    87
        TWO(2),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    88
        THREE(3);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    89
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    90
        int n;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    91
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    92
        private TypeArgArity(int n) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    93
            this.n = n;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    94
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    95
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    96
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    97
    enum TypeArgumentKind {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    98
        NONE(""),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
    99
        STRING("String"),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   100
        INTEGER("Integer");
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   101
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   102
        String typeargStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   103
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   104
        private TypeArgumentKind(String typeargStr) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   105
            this.typeargStr = typeargStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   106
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   107
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   108
        String getArgs(TypeArgArity arity) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   109
            if (this == NONE) return "";
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   110
            else {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   111
                StringBuilder buf = new StringBuilder();
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   112
                String sep = "";
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   113
                for (int i = 0 ; i < arity.n ; i++) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   114
                    buf.append(sep);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   115
                    buf.append(typeargStr);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   116
                    sep = ",";
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   117
                }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   118
                return "<" + buf.toString() + ">";
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   119
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   120
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   121
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   122
        boolean matches(ArgumentKind ak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   123
            switch (ak) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   124
                case STRING: return this != INTEGER;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   125
                case INTEGER: return this != STRING;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   126
                default: return false;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   127
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   128
        }
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   129
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   130
        boolean matches(TypeArgumentKind other) {
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   131
            switch (other) {
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   132
                case STRING: return this != INTEGER;
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   133
                case INTEGER: return this != STRING;
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   134
                default: return true;
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   135
            }
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   136
        }
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   137
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   138
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   139
    enum ArgumentKind {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   140
        STRING("\"\""),
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   141
        INTEGER("1");
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   142
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   143
        String argStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   144
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   145
        private ArgumentKind(String argStr) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   146
            this.argStr = argStr;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   147
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   148
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   149
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   150
    public static void main(String... args) throws Exception {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   151
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   152
        //create default shared JavaCompiler - reused across multiple compilations
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   153
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   154
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   155
            for (BoundKind boundKind : BoundKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   156
                for (ConstructorKind constructorKind : ConstructorKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   157
                    for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   158
                        for (TypeArgArity arity : TypeArgArity.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   159
                            for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   160
                                for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   161
                                    for (ArgumentKind argKind : ArgumentKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   162
                                        new GenericConstructorAndDiamondTest(boundKind, constructorKind,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   163
                                                declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9604
diff changeset
   164
                                    }
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   165
                                }
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   166
                            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   167
                        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   168
                    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   169
                }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   170
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   171
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   172
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   173
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   174
    BoundKind boundKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   175
    ConstructorKind constructorKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   176
    TypeArgumentKind declTypeArgumentKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   177
    TypeArgArity useTypeArgArity;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   178
    TypeArgumentKind useTypeArgumentKind;
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   179
    TypeArgumentKind diamondTypeArgumentKind;
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   180
    ArgumentKind argumentKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   181
    JavaSource source;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   182
    DiagnosticChecker diagChecker;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   183
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   184
    GenericConstructorAndDiamondTest(BoundKind boundKind, ConstructorKind constructorKind,
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   185
            TypeArgumentKind declTypeArgumentKind, TypeArgArity useTypeArgArity,
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   186
            TypeArgumentKind useTypeArgumentKind, TypeArgumentKind diamondTypeArgumentKind,
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   187
            ArgumentKind argumentKind) {
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   188
        this.boundKind = boundKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   189
        this.constructorKind = constructorKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   190
        this.declTypeArgumentKind = declTypeArgumentKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   191
        this.useTypeArgArity = useTypeArgArity;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   192
        this.useTypeArgumentKind = useTypeArgumentKind;
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   193
        this.diamondTypeArgumentKind = diamondTypeArgumentKind;
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   194
        this.argumentKind = argumentKind;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   195
        this.source = new JavaSource();
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   196
        this.diagChecker = new DiagnosticChecker();
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   197
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   198
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   199
    class JavaSource extends SimpleJavaFileObject {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   200
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   201
        String template = "class Foo<X #BK> {\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   202
                              "#CK\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   203
                          "}\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   204
                          "class Test {\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   205
                              "void test() {\n" +
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   206
                                 "Foo#TA1 f = new #TA2 Foo<#TA3>(#A);\n" +
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   207
                              "}\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   208
                          "}\n";
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   209
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   210
        String source;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   211
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   212
        public JavaSource() {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   213
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   214
            source = template.replace("#BK", boundKind.boundStr).
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   215
                    replace("#CK", constructorKind.constrStr)
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   216
                    .replace("#TA1", declTypeArgumentKind.getArgs(TypeArgArity.ONE))
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   217
                    .replace("#TA2", useTypeArgumentKind.getArgs(useTypeArgArity))
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   218
                    .replace("#TA3", diamondTypeArgumentKind.typeargStr)
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   219
                    .replace("#A", argumentKind.argStr);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   220
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   221
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   222
        @Override
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   223
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   224
            return source;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   225
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   226
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   227
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   228
    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   229
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   230
                null, null, Arrays.asList(source));
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   231
        ct.analyze();
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   232
        check();
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   233
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   234
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   235
    void check() {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   236
        boolean badActual = !constructorKind.matches(argumentKind);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   237
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   238
        boolean badArity = constructorKind != ConstructorKind.NON_GENERIC &&
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   239
                useTypeArgumentKind != TypeArgumentKind.NONE &&
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   240
                useTypeArgArity != TypeArgArity.ONE;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   241
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   242
        boolean badMethodTypeArg = constructorKind != ConstructorKind.NON_GENERIC &&
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   243
                !useTypeArgumentKind.matches(argumentKind);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   244
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   245
        boolean badExplicitParams = (useTypeArgumentKind != TypeArgumentKind.NONE &&
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   246
                diamondTypeArgumentKind == TypeArgumentKind.NONE) ||
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   247
                !boundKind.matches(diamondTypeArgumentKind);
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   248
9604
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   249
        boolean badGenericType = !boundKind.matches(declTypeArgumentKind) ||
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   250
                !diamondTypeArgumentKind.matches(declTypeArgumentKind);
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   251
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   252
        boolean shouldFail = badActual || badArity ||
d7152128d22f 7039931: Project Coin: diamond inference fail with generic constructor explicit type-arguments
mcimadamore
parents: 9075
diff changeset
   253
                badMethodTypeArg || badExplicitParams || badGenericType;
9075
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   254
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   255
        if (shouldFail != diagChecker.errorFound) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   256
            throw new Error("invalid diagnostics for source:\n" +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   257
                source.getCharContent(true) +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   258
                "\nFound error: " + diagChecker.errorFound +
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   259
                "\nExpected error: " + shouldFail);
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   260
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   261
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   262
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   263
    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   264
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   265
        boolean errorFound;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   266
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   267
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   268
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   269
                errorFound = true;
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   270
            }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   271
        }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   272
    }
cba34854a40e 7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
diff changeset
   273
}