1.1 --- a/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java Fri Apr 29 16:06:28 2011 +0100 1.2 +++ b/test/tools/javac/generics/diamond/7030150/GenericConstructorAndDiamondTest.java Sat Apr 30 11:57:46 2011 +0100 1.3 @@ -23,7 +23,7 @@ 1.4 1.5 /* 1.6 * @test 1.7 - * @bug 7030150 1.8 + * @bug 7030150 7039931 1.9 * @summary Type inference for generic instance creation failed for formal type parameter 1.10 */ 1.11 1.12 @@ -125,6 +125,14 @@ 1.13 default: return false; 1.14 } 1.15 } 1.16 + 1.17 + boolean matches(TypeArgumentKind other) { 1.18 + switch (other) { 1.19 + case STRING: return this != INTEGER; 1.20 + case INTEGER: return this != STRING; 1.21 + default: return true; 1.22 + } 1.23 + } 1.24 } 1.25 1.26 enum ArgumentKind { 1.27 @@ -149,9 +157,11 @@ 1.28 for (TypeArgumentKind declArgKind : TypeArgumentKind.values()) { 1.29 for (TypeArgArity arity : TypeArgArity.values()) { 1.30 for (TypeArgumentKind useArgKind : TypeArgumentKind.values()) { 1.31 - for (ArgumentKind argKind : ArgumentKind.values()) { 1.32 - new GenericConstructorAndDiamondTest(boundKind, constructorKind, 1.33 - declArgKind, arity, useArgKind, argKind).run(comp, fm); 1.34 + for (TypeArgumentKind diamondArgKind : TypeArgumentKind.values()) { 1.35 + for (ArgumentKind argKind : ArgumentKind.values()) { 1.36 + new GenericConstructorAndDiamondTest(boundKind, constructorKind, 1.37 + declArgKind, arity, useArgKind, diamondArgKind, argKind).run(comp, fm); 1.38 + } 1.39 } 1.40 } 1.41 } 1.42 @@ -165,18 +175,21 @@ 1.43 TypeArgumentKind declTypeArgumentKind; 1.44 TypeArgArity useTypeArgArity; 1.45 TypeArgumentKind useTypeArgumentKind; 1.46 + TypeArgumentKind diamondTypeArgumentKind; 1.47 ArgumentKind argumentKind; 1.48 JavaSource source; 1.49 DiagnosticChecker diagChecker; 1.50 1.51 GenericConstructorAndDiamondTest(BoundKind boundKind, ConstructorKind constructorKind, 1.52 TypeArgumentKind declTypeArgumentKind, TypeArgArity useTypeArgArity, 1.53 - TypeArgumentKind useTypeArgumentKind, ArgumentKind argumentKind) { 1.54 + TypeArgumentKind useTypeArgumentKind, TypeArgumentKind diamondTypeArgumentKind, 1.55 + ArgumentKind argumentKind) { 1.56 this.boundKind = boundKind; 1.57 this.constructorKind = constructorKind; 1.58 this.declTypeArgumentKind = declTypeArgumentKind; 1.59 this.useTypeArgArity = useTypeArgArity; 1.60 this.useTypeArgumentKind = useTypeArgumentKind; 1.61 + this.diamondTypeArgumentKind = diamondTypeArgumentKind; 1.62 this.argumentKind = argumentKind; 1.63 this.source = new JavaSource(); 1.64 this.diagChecker = new DiagnosticChecker(); 1.65 @@ -189,7 +202,7 @@ 1.66 "}\n" + 1.67 "class Test {\n" + 1.68 "void test() {\n" + 1.69 - "Foo#TA1 f = new #TA2 Foo<>(#A);\n" + 1.70 + "Foo#TA1 f = new #TA2 Foo<#TA3>(#A);\n" + 1.71 "}\n" + 1.72 "}\n"; 1.73 1.74 @@ -201,6 +214,7 @@ 1.75 replace("#CK", constructorKind.constrStr) 1.76 .replace("#TA1", declTypeArgumentKind.getArgs(TypeArgArity.ONE)) 1.77 .replace("#TA2", useTypeArgumentKind.getArgs(useTypeArgArity)) 1.78 + .replace("#TA3", diamondTypeArgumentKind.typeargStr) 1.79 .replace("#A", argumentKind.argStr); 1.80 } 1.81 1.82 @@ -227,9 +241,15 @@ 1.83 boolean badMethodTypeArg = constructorKind != ConstructorKind.NON_GENERIC && 1.84 !useTypeArgumentKind.matches(argumentKind); 1.85 1.86 - boolean badGenericType = !boundKind.matches(declTypeArgumentKind); 1.87 + boolean badExplicitParams = (useTypeArgumentKind != TypeArgumentKind.NONE && 1.88 + diamondTypeArgumentKind == TypeArgumentKind.NONE) || 1.89 + !boundKind.matches(diamondTypeArgumentKind); 1.90 1.91 - boolean shouldFail = badActual || badArity || badMethodTypeArg || badGenericType; 1.92 + boolean badGenericType = !boundKind.matches(declTypeArgumentKind) || 1.93 + !diamondTypeArgumentKind.matches(declTypeArgumentKind); 1.94 + 1.95 + boolean shouldFail = badActual || badArity || 1.96 + badMethodTypeArg || badExplicitParams || badGenericType; 1.97 1.98 if (shouldFail != diagChecker.errorFound) { 1.99 throw new Error("invalid diagnostics for source:\n" +