Thu, 03 Feb 2011 09:36:28 +0000
5017953: spurious cascaded diagnostics when name not found
Summary: when an operator is applied to one or more erroneous operands, spurious diagnostics are generated
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 7006109
27 * @summary Add test library to simplify the task of writing automated type-system tests
28 * @author mcimadamore
29 * @library .
30 * @run main CastTest
31 */
33 import com.sun.tools.javac.code.Type;
34 import com.sun.tools.javac.code.Type.*;
35 import com.sun.tools.javac.code.Symbol.*;
36 import java.lang.reflect.Array;
38 import static com.sun.tools.javac.code.Flags.*;
40 /**
41 * Check invariants in cast conversion involving primitive types and arrays
42 */
43 public class CastTest extends TypeHarness {
45 Type[] allTypes;
47 static final boolean T = true;
48 static final boolean F = false;
50 boolean[][] cast_result = {
51 //byte, short, int, long, float, double, char, bool, C, +C, I, T, byte[], short[], int[], long[], float[], double[], char[], bool[], C[], +C[], I[], T[]
52 /*byte*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
53 /*short*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
54 /*int*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
55 /*long*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
56 /*float*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
57 /*double*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
58 /*char*/ { T , T , T , T , T , T , T , F , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
59 /*bool*/ { F , F , F , F , F , F , F , T , F, F , F, F, F , F , F , F , F , F , F , F , F , F , F , F },
60 /*C*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F },
61 /*+C*/ { F , F , F , F , F , F , F , F , F, T , F, T, F , F , F , F , F , F , F , F , F , F , F , F },
62 /*I*/ { F , F , F , F , F , F , F , F , T, F , T, T, F , F , F , F , F , F , F , F , F , F , F , F },
63 /*T*/ { F , F , F , F , F , F , F , F , T, T , T, T, T , T , T , T , T , T , T , T , T , T , T , T },
64 /*byte[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, T , F , F , F , F , F , F , F , F , F , F , F },
65 /*short[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , T , F , F , F , F , F , F , F , F , F , F },
66 /*int[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , T , F , F , F , F , F , F , F , F , F },
67 /*long[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , T , F , F , F , F , F , F , F , F },
68 /*float[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , T , F , F , F , F , F , F , F },
69 /*double[]*/{ F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , T , F , F , F , F , F , F },
70 /*char[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , T , F , F , F , F , F },
71 /*bool[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , T , F , F , F , F },
72 /*C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T },
73 /*+C[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , F , T , F , T },
74 /*I[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , F , T , T },
75 /*T[]*/ { F , F , F , F , F , F , F , F , F, F , F, T, F , F , F , F , F , F , F , F , T , T , T , T }};
77 CastTest() {
78 Type[] primitiveTypes = {
79 predef.byteType,
80 predef.shortType,
81 predef.intType,
82 predef.longType,
83 predef.floatType,
84 predef.doubleType,
85 predef.charType,
86 predef.booleanType };
88 Type[] referenceTypes = {
89 fac.Class(),
90 fac.Class(FINAL),
91 fac.Interface(),
92 fac.TypeVariable() };
94 Type[] arrayTypes = new Type[primitiveTypes.length + referenceTypes.length];
95 int idx = 0;
96 for (Type t : join(Type.class, primitiveTypes, referenceTypes)) {
97 arrayTypes[idx++] = fac.Array(t);
98 }
100 allTypes = join(Type.class, primitiveTypes, referenceTypes, arrayTypes);
101 }
103 void test() {
104 for (int i = 0; i < allTypes.length ; i++) {
105 for (int j = 0; j < allTypes.length ; j++) {
106 assertCastable(allTypes[i], allTypes[j], cast_result[i][j]);
107 }
108 }
109 }
111 @SuppressWarnings("unchecked")
112 <T> T[] join(Class<T> type, T[]... args) {
113 int totalLength = 0;
114 for (T[] arr : args) {
115 totalLength += arr.length;
116 }
117 T[] new_arr = (T[])Array.newInstance(type, totalLength);
118 int idx = 0;
119 for (T[] arr : args) {
120 System.arraycopy(arr, 0, new_arr, idx, arr.length);
121 idx += arr.length;
122 }
123 return new_arr;
124 }
126 public static void main(String[] args) {
127 new CastTest().test();
128 }
129 }