author | jjg |
Mon, 25 Apr 2011 15:56:09 -0700 | |
changeset 9595 | a7dea6cbd5f7 |
parent 9303 | eae35c201e19 |
child 9602 | 5efe2fa1581a |
permissions | -rw-r--r-- |
10 | 1 |
/* |
8032 | 2 |
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
28 |
import java.lang.ref.SoftReference; |
10 | 29 |
import java.util.*; |
30 |
||
31 |
import com.sun.tools.javac.util.*; |
|
32 |
import com.sun.tools.javac.util.List; |
|
33 |
||
34 |
import com.sun.tools.javac.jvm.ClassReader; |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
35 |
import com.sun.tools.javac.code.Attribute.RetentionPolicy; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
36 |
import com.sun.tools.javac.code.Lint.LintCategory; |
10 | 37 |
import com.sun.tools.javac.comp.Check; |
38 |
||
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
39 |
import static com.sun.tools.javac.code.Scope.*; |
10 | 40 |
import static com.sun.tools.javac.code.Type.*; |
41 |
import static com.sun.tools.javac.code.TypeTags.*; |
|
42 |
import static com.sun.tools.javac.code.Symbol.*; |
|
43 |
import static com.sun.tools.javac.code.Flags.*; |
|
44 |
import static com.sun.tools.javac.code.BoundKind.*; |
|
45 |
import static com.sun.tools.javac.util.ListBuffer.lb; |
|
46 |
||
47 |
/** |
|
48 |
* Utility class containing various operations on types. |
|
49 |
* |
|
50 |
* <p>Unless other names are more illustrative, the following naming |
|
51 |
* conventions should be observed in this file: |
|
52 |
* |
|
53 |
* <dl> |
|
54 |
* <dt>t</dt> |
|
55 |
* <dd>If the first argument to an operation is a type, it should be named t.</dd> |
|
56 |
* <dt>s</dt> |
|
57 |
* <dd>Similarly, if the second argument to an operation is a type, it should be named s.</dd> |
|
58 |
* <dt>ts</dt> |
|
59 |
* <dd>If an operations takes a list of types, the first should be named ts.</dd> |
|
60 |
* <dt>ss</dt> |
|
61 |
* <dd>A second list of types should be named ss.</dd> |
|
62 |
* </dl> |
|
63 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5654
diff
changeset
|
64 |
* <p><b>This is NOT part of any supported API. |
10 | 65 |
* If you write code that depends on this, you do so at your own risk. |
66 |
* This code and its internal interfaces are subject to change or |
|
67 |
* deletion without notice.</b> |
|
68 |
*/ |
|
69 |
public class Types { |
|
70 |
protected static final Context.Key<Types> typesKey = |
|
71 |
new Context.Key<Types>(); |
|
72 |
||
73 |
final Symtab syms; |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1469
diff
changeset
|
74 |
final JavacMessages messages; |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
75 |
final Names names; |
10 | 76 |
final boolean allowBoxing; |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
77 |
final boolean allowCovariantReturns; |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
78 |
final boolean allowObjectToPrimitiveCast; |
10 | 79 |
final ClassReader reader; |
80 |
final Check chk; |
|
81 |
List<Warner> warnStack = List.nil(); |
|
82 |
final Name capturedName; |
|
83 |
||
84 |
// <editor-fold defaultstate="collapsed" desc="Instantiating"> |
|
85 |
public static Types instance(Context context) { |
|
86 |
Types instance = context.get(typesKey); |
|
87 |
if (instance == null) |
|
88 |
instance = new Types(context); |
|
89 |
return instance; |
|
90 |
} |
|
91 |
||
92 |
protected Types(Context context) { |
|
93 |
context.put(typesKey, this); |
|
94 |
syms = Symtab.instance(context); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
95 |
names = Names.instance(context); |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
96 |
Source source = Source.instance(context); |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
97 |
allowBoxing = source.allowBoxing(); |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
98 |
allowCovariantReturns = source.allowCovariantReturns(); |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
99 |
allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); |
10 | 100 |
reader = ClassReader.instance(context); |
101 |
chk = Check.instance(context); |
|
102 |
capturedName = names.fromString("<captured wildcard>"); |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1469
diff
changeset
|
103 |
messages = JavacMessages.instance(context); |
10 | 104 |
} |
105 |
// </editor-fold> |
|
106 |
||
107 |
// <editor-fold defaultstate="collapsed" desc="upperBound"> |
|
108 |
/** |
|
109 |
* The "rvalue conversion".<br> |
|
110 |
* The upper bound of most types is the type |
|
111 |
* itself. Wildcards, on the other hand have upper |
|
112 |
* and lower bounds. |
|
113 |
* @param t a type |
|
114 |
* @return the upper bound of the given type |
|
115 |
*/ |
|
116 |
public Type upperBound(Type t) { |
|
117 |
return upperBound.visit(t); |
|
118 |
} |
|
119 |
// where |
|
120 |
private final MapVisitor<Void> upperBound = new MapVisitor<Void>() { |
|
121 |
||
122 |
@Override |
|
123 |
public Type visitWildcardType(WildcardType t, Void ignored) { |
|
124 |
if (t.isSuperBound()) |
|
125 |
return t.bound == null ? syms.objectType : t.bound.bound; |
|
126 |
else |
|
127 |
return visit(t.type); |
|
128 |
} |
|
129 |
||
130 |
@Override |
|
131 |
public Type visitCapturedType(CapturedType t, Void ignored) { |
|
132 |
return visit(t.bound); |
|
133 |
} |
|
134 |
}; |
|
135 |
// </editor-fold> |
|
136 |
||
137 |
// <editor-fold defaultstate="collapsed" desc="lowerBound"> |
|
138 |
/** |
|
139 |
* The "lvalue conversion".<br> |
|
140 |
* The lower bound of most types is the type |
|
141 |
* itself. Wildcards, on the other hand have upper |
|
142 |
* and lower bounds. |
|
143 |
* @param t a type |
|
144 |
* @return the lower bound of the given type |
|
145 |
*/ |
|
146 |
public Type lowerBound(Type t) { |
|
147 |
return lowerBound.visit(t); |
|
148 |
} |
|
149 |
// where |
|
150 |
private final MapVisitor<Void> lowerBound = new MapVisitor<Void>() { |
|
151 |
||
152 |
@Override |
|
153 |
public Type visitWildcardType(WildcardType t, Void ignored) { |
|
154 |
return t.isExtendsBound() ? syms.botType : visit(t.type); |
|
155 |
} |
|
156 |
||
157 |
@Override |
|
158 |
public Type visitCapturedType(CapturedType t, Void ignored) { |
|
159 |
return visit(t.getLowerBound()); |
|
160 |
} |
|
161 |
}; |
|
162 |
// </editor-fold> |
|
163 |
||
164 |
// <editor-fold defaultstate="collapsed" desc="isUnbounded"> |
|
165 |
/** |
|
166 |
* Checks that all the arguments to a class are unbounded |
|
167 |
* wildcards or something else that doesn't make any restrictions |
|
168 |
* on the arguments. If a class isUnbounded, a raw super- or |
|
169 |
* subclass can be cast to it without a warning. |
|
170 |
* @param t a type |
|
171 |
* @return true iff the given type is unbounded or raw |
|
172 |
*/ |
|
173 |
public boolean isUnbounded(Type t) { |
|
174 |
return isUnbounded.visit(t); |
|
175 |
} |
|
176 |
// where |
|
177 |
private final UnaryVisitor<Boolean> isUnbounded = new UnaryVisitor<Boolean>() { |
|
178 |
||
179 |
public Boolean visitType(Type t, Void ignored) { |
|
180 |
return true; |
|
181 |
} |
|
182 |
||
183 |
@Override |
|
184 |
public Boolean visitClassType(ClassType t, Void ignored) { |
|
185 |
List<Type> parms = t.tsym.type.allparams(); |
|
186 |
List<Type> args = t.allparams(); |
|
187 |
while (parms.nonEmpty()) { |
|
188 |
WildcardType unb = new WildcardType(syms.objectType, |
|
189 |
BoundKind.UNBOUND, |
|
190 |
syms.boundClass, |
|
191 |
(TypeVar)parms.head); |
|
192 |
if (!containsType(args.head, unb)) |
|
193 |
return false; |
|
194 |
parms = parms.tail; |
|
195 |
args = args.tail; |
|
196 |
} |
|
197 |
return true; |
|
198 |
} |
|
199 |
}; |
|
200 |
// </editor-fold> |
|
201 |
||
202 |
// <editor-fold defaultstate="collapsed" desc="asSub"> |
|
203 |
/** |
|
204 |
* Return the least specific subtype of t that starts with symbol |
|
205 |
* sym. If none exists, return null. The least specific subtype |
|
206 |
* is determined as follows: |
|
207 |
* |
|
208 |
* <p>If there is exactly one parameterized instance of sym that is a |
|
209 |
* subtype of t, that parameterized instance is returned.<br> |
|
210 |
* Otherwise, if the plain type or raw type `sym' is a subtype of |
|
211 |
* type t, the type `sym' itself is returned. Otherwise, null is |
|
212 |
* returned. |
|
213 |
*/ |
|
214 |
public Type asSub(Type t, Symbol sym) { |
|
215 |
return asSub.visit(t, sym); |
|
216 |
} |
|
217 |
// where |
|
218 |
private final SimpleVisitor<Type,Symbol> asSub = new SimpleVisitor<Type,Symbol>() { |
|
219 |
||
220 |
public Type visitType(Type t, Symbol sym) { |
|
221 |
return null; |
|
222 |
} |
|
223 |
||
224 |
@Override |
|
225 |
public Type visitClassType(ClassType t, Symbol sym) { |
|
226 |
if (t.tsym == sym) |
|
227 |
return t; |
|
228 |
Type base = asSuper(sym.type, t.tsym); |
|
229 |
if (base == null) |
|
230 |
return null; |
|
231 |
ListBuffer<Type> from = new ListBuffer<Type>(); |
|
232 |
ListBuffer<Type> to = new ListBuffer<Type>(); |
|
233 |
try { |
|
234 |
adapt(base, t, from, to); |
|
235 |
} catch (AdaptFailure ex) { |
|
236 |
return null; |
|
237 |
} |
|
238 |
Type res = subst(sym.type, from.toList(), to.toList()); |
|
239 |
if (!isSubtype(res, t)) |
|
240 |
return null; |
|
241 |
ListBuffer<Type> openVars = new ListBuffer<Type>(); |
|
242 |
for (List<Type> l = sym.type.allparams(); |
|
243 |
l.nonEmpty(); l = l.tail) |
|
244 |
if (res.contains(l.head) && !t.contains(l.head)) |
|
245 |
openVars.append(l.head); |
|
246 |
if (openVars.nonEmpty()) { |
|
247 |
if (t.isRaw()) { |
|
248 |
// The subtype of a raw type is raw |
|
249 |
res = erasure(res); |
|
250 |
} else { |
|
251 |
// Unbound type arguments default to ? |
|
252 |
List<Type> opens = openVars.toList(); |
|
253 |
ListBuffer<Type> qs = new ListBuffer<Type>(); |
|
254 |
for (List<Type> iter = opens; iter.nonEmpty(); iter = iter.tail) { |
|
255 |
qs.append(new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass, (TypeVar) iter.head)); |
|
256 |
} |
|
257 |
res = subst(res, opens, qs.toList()); |
|
258 |
} |
|
259 |
} |
|
260 |
return res; |
|
261 |
} |
|
262 |
||
263 |
@Override |
|
264 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
|
265 |
return t; |
|
266 |
} |
|
267 |
}; |
|
268 |
// </editor-fold> |
|
269 |
||
270 |
// <editor-fold defaultstate="collapsed" desc="isConvertible"> |
|
271 |
/** |
|
272 |
* Is t a subtype of or convertiable via boxing/unboxing |
|
273 |
* convertions to s? |
|
274 |
*/ |
|
275 |
public boolean isConvertible(Type t, Type s, Warner warn) { |
|
276 |
boolean tPrimitive = t.isPrimitive(); |
|
277 |
boolean sPrimitive = s.isPrimitive(); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
278 |
if (tPrimitive == sPrimitive) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
279 |
checkUnsafeVarargsConversion(t, s, warn); |
10 | 280 |
return isSubtypeUnchecked(t, s, warn); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
281 |
} |
10 | 282 |
if (!allowBoxing) return false; |
283 |
return tPrimitive |
|
284 |
? isSubtype(boxedClass(t).type, s) |
|
285 |
: isSubtype(unboxedType(t), s); |
|
286 |
} |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
287 |
//where |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
288 |
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
289 |
if (t.tag != ARRAY || isReifiable(t)) return; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
290 |
ArrayType from = (ArrayType)t; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
291 |
boolean shouldWarn = false; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
292 |
switch (s.tag) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
293 |
case ARRAY: |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
294 |
ArrayType to = (ArrayType)s; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
295 |
shouldWarn = from.isVarargs() && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
296 |
!to.isVarargs() && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
297 |
!isReifiable(from); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
298 |
break; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
299 |
case CLASS: |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
300 |
shouldWarn = from.isVarargs() && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
301 |
isSubtype(from, s); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
302 |
break; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
303 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
304 |
if (shouldWarn) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
305 |
warn.warn(LintCategory.VARARGS); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
306 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
307 |
} |
10 | 308 |
|
309 |
/** |
|
310 |
* Is t a subtype of or convertiable via boxing/unboxing |
|
311 |
* convertions to s? |
|
312 |
*/ |
|
313 |
public boolean isConvertible(Type t, Type s) { |
|
314 |
return isConvertible(t, s, Warner.noWarnings); |
|
315 |
} |
|
316 |
// </editor-fold> |
|
317 |
||
318 |
// <editor-fold defaultstate="collapsed" desc="isSubtype"> |
|
319 |
/** |
|
320 |
* Is t an unchecked subtype of s? |
|
321 |
*/ |
|
322 |
public boolean isSubtypeUnchecked(Type t, Type s) { |
|
323 |
return isSubtypeUnchecked(t, s, Warner.noWarnings); |
|
324 |
} |
|
325 |
/** |
|
326 |
* Is t an unchecked subtype of s? |
|
327 |
*/ |
|
328 |
public boolean isSubtypeUnchecked(Type t, Type s, Warner warn) { |
|
329 |
if (t.tag == ARRAY && s.tag == ARRAY) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
330 |
if (((ArrayType)t).elemtype.tag <= lastBaseTag) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
331 |
return isSameType(elemtype(t), elemtype(s)); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
332 |
} else { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
333 |
ArrayType from = (ArrayType)t; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
334 |
ArrayType to = (ArrayType)s; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
335 |
if (from.isVarargs() && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
336 |
!to.isVarargs() && |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
337 |
!isReifiable(from)) { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
338 |
warn.warn(LintCategory.VARARGS); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
339 |
} |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
340 |
return isSubtypeUnchecked(elemtype(t), elemtype(s), warn); |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
341 |
} |
10 | 342 |
} else if (isSubtype(t, s)) { |
343 |
return true; |
|
660
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
344 |
} |
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
345 |
else if (t.tag == TYPEVAR) { |
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
346 |
return isSubtypeUnchecked(t.getUpperBound(), s, warn); |
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
347 |
} |
1044
7016e624ec3a
6718364: inference fails when a generic method is invoked with raw arguments
mcimadamore
parents:
938
diff
changeset
|
348 |
else if (s.tag == UNDETVAR) { |
7016e624ec3a
6718364: inference fails when a generic method is invoked with raw arguments
mcimadamore
parents:
938
diff
changeset
|
349 |
UndetVar uv = (UndetVar)s; |
7016e624ec3a
6718364: inference fails when a generic method is invoked with raw arguments
mcimadamore
parents:
938
diff
changeset
|
350 |
if (uv.inst != null) |
7016e624ec3a
6718364: inference fails when a generic method is invoked with raw arguments
mcimadamore
parents:
938
diff
changeset
|
351 |
return isSubtypeUnchecked(t, uv.inst, warn); |
7016e624ec3a
6718364: inference fails when a generic method is invoked with raw arguments
mcimadamore
parents:
938
diff
changeset
|
352 |
} |
660
16c478b6af1d
6507024: casting an array to a generic type results in a 'capture#69 of ?' type error
mcimadamore
parents:
514
diff
changeset
|
353 |
else if (!s.isRaw()) { |
10 | 354 |
Type t2 = asSuper(t, s.tsym); |
355 |
if (t2 != null && t2.isRaw()) { |
|
356 |
if (isReifiable(s)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
357 |
warn.silentWarn(LintCategory.UNCHECKED); |
10 | 358 |
else |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
359 |
warn.warn(LintCategory.UNCHECKED); |
10 | 360 |
return true; |
361 |
} |
|
362 |
} |
|
363 |
return false; |
|
364 |
} |
|
365 |
||
366 |
/** |
|
367 |
* Is t a subtype of s?<br> |
|
368 |
* (not defined for Method and ForAll types) |
|
369 |
*/ |
|
370 |
final public boolean isSubtype(Type t, Type s) { |
|
371 |
return isSubtype(t, s, true); |
|
372 |
} |
|
373 |
final public boolean isSubtypeNoCapture(Type t, Type s) { |
|
374 |
return isSubtype(t, s, false); |
|
375 |
} |
|
376 |
public boolean isSubtype(Type t, Type s, boolean capture) { |
|
377 |
if (t == s) |
|
378 |
return true; |
|
379 |
||
380 |
if (s.tag >= firstPartialTag) |
|
381 |
return isSuperType(s, t); |
|
382 |
||
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
383 |
if (s.isCompound()) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
384 |
for (Type s2 : interfaces(s).prepend(supertype(s))) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
385 |
if (!isSubtype(t, s2, capture)) |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
386 |
return false; |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
387 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
388 |
return true; |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
389 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
390 |
|
10 | 391 |
Type lower = lowerBound(s); |
392 |
if (s != lower) |
|
393 |
return isSubtype(capture ? capture(t) : t, lower, false); |
|
394 |
||
395 |
return isSubtype.visit(capture ? capture(t) : t, s); |
|
396 |
} |
|
397 |
// where |
|
398 |
private TypeRelation isSubtype = new TypeRelation() |
|
399 |
{ |
|
400 |
public Boolean visitType(Type t, Type s) { |
|
401 |
switch (t.tag) { |
|
402 |
case BYTE: case CHAR: |
|
403 |
return (t.tag == s.tag || |
|
404 |
t.tag + 2 <= s.tag && s.tag <= DOUBLE); |
|
405 |
case SHORT: case INT: case LONG: case FLOAT: case DOUBLE: |
|
406 |
return t.tag <= s.tag && s.tag <= DOUBLE; |
|
407 |
case BOOLEAN: case VOID: |
|
408 |
return t.tag == s.tag; |
|
409 |
case TYPEVAR: |
|
410 |
return isSubtypeNoCapture(t.getUpperBound(), s); |
|
411 |
case BOT: |
|
412 |
return |
|
413 |
s.tag == BOT || s.tag == CLASS || |
|
414 |
s.tag == ARRAY || s.tag == TYPEVAR; |
|
415 |
case NONE: |
|
416 |
return false; |
|
417 |
default: |
|
418 |
throw new AssertionError("isSubtype " + t.tag); |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
private Set<TypePair> cache = new HashSet<TypePair>(); |
|
423 |
||
424 |
private boolean containsTypeRecursive(Type t, Type s) { |
|
425 |
TypePair pair = new TypePair(t, s); |
|
426 |
if (cache.add(pair)) { |
|
427 |
try { |
|
428 |
return containsType(t.getTypeArguments(), |
|
429 |
s.getTypeArguments()); |
|
430 |
} finally { |
|
431 |
cache.remove(pair); |
|
432 |
} |
|
433 |
} else { |
|
434 |
return containsType(t.getTypeArguments(), |
|
435 |
rewriteSupers(s).getTypeArguments()); |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
private Type rewriteSupers(Type t) { |
|
440 |
if (!t.isParameterized()) |
|
441 |
return t; |
|
442 |
ListBuffer<Type> from = lb(); |
|
443 |
ListBuffer<Type> to = lb(); |
|
444 |
adaptSelf(t, from, to); |
|
445 |
if (from.isEmpty()) |
|
446 |
return t; |
|
447 |
ListBuffer<Type> rewrite = lb(); |
|
448 |
boolean changed = false; |
|
449 |
for (Type orig : to.toList()) { |
|
450 |
Type s = rewriteSupers(orig); |
|
451 |
if (s.isSuperBound() && !s.isExtendsBound()) { |
|
452 |
s = new WildcardType(syms.objectType, |
|
453 |
BoundKind.UNBOUND, |
|
454 |
syms.boundClass); |
|
455 |
changed = true; |
|
456 |
} else if (s != orig) { |
|
457 |
s = new WildcardType(upperBound(s), |
|
458 |
BoundKind.EXTENDS, |
|
459 |
syms.boundClass); |
|
460 |
changed = true; |
|
461 |
} |
|
462 |
rewrite.append(s); |
|
463 |
} |
|
464 |
if (changed) |
|
465 |
return subst(t.tsym.type, from.toList(), rewrite.toList()); |
|
466 |
else |
|
467 |
return t; |
|
468 |
} |
|
469 |
||
470 |
@Override |
|
471 |
public Boolean visitClassType(ClassType t, Type s) { |
|
472 |
Type sup = asSuper(t, s.tsym); |
|
473 |
return sup != null |
|
474 |
&& sup.tsym == s.tsym |
|
475 |
// You're not allowed to write |
|
476 |
// Vector<Object> vec = new Vector<String>(); |
|
477 |
// But with wildcards you can write |
|
478 |
// Vector<? extends Object> vec = new Vector<String>(); |
|
479 |
// which means that subtype checking must be done |
|
480 |
// here instead of same-type checking (via containsType). |
|
481 |
&& (!s.isParameterized() || containsTypeRecursive(s, sup)) |
|
482 |
&& isSubtypeNoCapture(sup.getEnclosingType(), |
|
483 |
s.getEnclosingType()); |
|
484 |
} |
|
485 |
||
486 |
@Override |
|
487 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
488 |
if (s.tag == ARRAY) { |
|
489 |
if (t.elemtype.tag <= lastBaseTag) |
|
490 |
return isSameType(t.elemtype, elemtype(s)); |
|
491 |
else |
|
492 |
return isSubtypeNoCapture(t.elemtype, elemtype(s)); |
|
493 |
} |
|
494 |
||
495 |
if (s.tag == CLASS) { |
|
496 |
Name sname = s.tsym.getQualifiedName(); |
|
497 |
return sname == names.java_lang_Object |
|
498 |
|| sname == names.java_lang_Cloneable |
|
499 |
|| sname == names.java_io_Serializable; |
|
500 |
} |
|
501 |
||
502 |
return false; |
|
503 |
} |
|
504 |
||
505 |
@Override |
|
506 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
507 |
//todo: test against origin needed? or replace with substitution? |
|
508 |
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) |
|
509 |
return true; |
|
510 |
||
511 |
if (t.inst != null) |
|
512 |
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"? |
|
513 |
||
514 |
t.hibounds = t.hibounds.prepend(s); |
|
515 |
return true; |
|
516 |
} |
|
517 |
||
518 |
@Override |
|
519 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
520 |
return true; |
|
521 |
} |
|
522 |
}; |
|
523 |
||
524 |
/** |
|
525 |
* Is t a subtype of every type in given list `ts'?<br> |
|
526 |
* (not defined for Method and ForAll types)<br> |
|
527 |
* Allows unchecked conversions. |
|
528 |
*/ |
|
529 |
public boolean isSubtypeUnchecked(Type t, List<Type> ts, Warner warn) { |
|
530 |
for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
|
531 |
if (!isSubtypeUnchecked(t, l.head, warn)) |
|
532 |
return false; |
|
533 |
return true; |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* Are corresponding elements of ts subtypes of ss? If lists are |
|
538 |
* of different length, return false. |
|
539 |
*/ |
|
540 |
public boolean isSubtypes(List<Type> ts, List<Type> ss) { |
|
541 |
while (ts.tail != null && ss.tail != null |
|
542 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
543 |
isSubtype(ts.head, ss.head)) { |
|
544 |
ts = ts.tail; |
|
545 |
ss = ss.tail; |
|
546 |
} |
|
547 |
return ts.tail == null && ss.tail == null; |
|
548 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
549 |
} |
|
550 |
||
551 |
/** |
|
552 |
* Are corresponding elements of ts subtypes of ss, allowing |
|
553 |
* unchecked conversions? If lists are of different length, |
|
554 |
* return false. |
|
555 |
**/ |
|
556 |
public boolean isSubtypesUnchecked(List<Type> ts, List<Type> ss, Warner warn) { |
|
557 |
while (ts.tail != null && ss.tail != null |
|
558 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
559 |
isSubtypeUnchecked(ts.head, ss.head, warn)) { |
|
560 |
ts = ts.tail; |
|
561 |
ss = ss.tail; |
|
562 |
} |
|
563 |
return ts.tail == null && ss.tail == null; |
|
564 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
565 |
} |
|
566 |
// </editor-fold> |
|
567 |
||
568 |
// <editor-fold defaultstate="collapsed" desc="isSuperType"> |
|
569 |
/** |
|
570 |
* Is t a supertype of s? |
|
571 |
*/ |
|
572 |
public boolean isSuperType(Type t, Type s) { |
|
573 |
switch (t.tag) { |
|
574 |
case ERROR: |
|
575 |
return true; |
|
576 |
case UNDETVAR: { |
|
577 |
UndetVar undet = (UndetVar)t; |
|
578 |
if (t == s || |
|
579 |
undet.qtype == s || |
|
580 |
s.tag == ERROR || |
|
581 |
s.tag == BOT) return true; |
|
582 |
if (undet.inst != null) |
|
583 |
return isSubtype(s, undet.inst); |
|
584 |
undet.lobounds = undet.lobounds.prepend(s); |
|
585 |
return true; |
|
586 |
} |
|
587 |
default: |
|
588 |
return isSubtype(s, t); |
|
589 |
} |
|
590 |
} |
|
591 |
// </editor-fold> |
|
592 |
||
593 |
// <editor-fold defaultstate="collapsed" desc="isSameType"> |
|
594 |
/** |
|
595 |
* Are corresponding elements of the lists the same type? If |
|
596 |
* lists are of different length, return false. |
|
597 |
*/ |
|
598 |
public boolean isSameTypes(List<Type> ts, List<Type> ss) { |
|
599 |
while (ts.tail != null && ss.tail != null |
|
600 |
/*inlined: ts.nonEmpty() && ss.nonEmpty()*/ && |
|
601 |
isSameType(ts.head, ss.head)) { |
|
602 |
ts = ts.tail; |
|
603 |
ss = ss.tail; |
|
604 |
} |
|
605 |
return ts.tail == null && ss.tail == null; |
|
606 |
/*inlined: ts.isEmpty() && ss.isEmpty();*/ |
|
607 |
} |
|
608 |
||
609 |
/** |
|
610 |
* Is t the same type as s? |
|
611 |
*/ |
|
612 |
public boolean isSameType(Type t, Type s) { |
|
613 |
return isSameType.visit(t, s); |
|
614 |
} |
|
615 |
// where |
|
616 |
private TypeRelation isSameType = new TypeRelation() { |
|
617 |
||
618 |
public Boolean visitType(Type t, Type s) { |
|
619 |
if (t == s) |
|
620 |
return true; |
|
621 |
||
622 |
if (s.tag >= firstPartialTag) |
|
623 |
return visit(s, t); |
|
624 |
||
625 |
switch (t.tag) { |
|
626 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
|
627 |
case DOUBLE: case BOOLEAN: case VOID: case BOT: case NONE: |
|
628 |
return t.tag == s.tag; |
|
5648
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
629 |
case TYPEVAR: { |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
630 |
if (s.tag == TYPEVAR) { |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
631 |
//type-substitution does not preserve type-var types |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
632 |
//check that type var symbols and bounds are indeed the same |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
633 |
return t.tsym == s.tsym && |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
634 |
visit(t.getUpperBound(), s.getUpperBound()); |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
635 |
} |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
636 |
else { |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
637 |
//special case for s == ? super X, where upper(s) = u |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
638 |
//check that u == t, where u has been set by Type.withTypeVar |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
639 |
return s.isSuperBound() && |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
640 |
!s.isExtendsBound() && |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
641 |
visit(t, upperBound(s)); |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
642 |
} |
e8aa492874b5
6880344: Recursive type parameters do not compile
mcimadamore
parents:
5004
diff
changeset
|
643 |
} |
10 | 644 |
default: |
645 |
throw new AssertionError("isSameType " + t.tag); |
|
646 |
} |
|
647 |
} |
|
648 |
||
649 |
@Override |
|
650 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
651 |
if (s.tag >= firstPartialTag) |
|
652 |
return visit(s, t); |
|
653 |
else |
|
654 |
return false; |
|
655 |
} |
|
656 |
||
657 |
@Override |
|
658 |
public Boolean visitClassType(ClassType t, Type s) { |
|
659 |
if (t == s) |
|
660 |
return true; |
|
661 |
||
662 |
if (s.tag >= firstPartialTag) |
|
663 |
return visit(s, t); |
|
664 |
||
665 |
if (s.isSuperBound() && !s.isExtendsBound()) |
|
666 |
return visit(t, upperBound(s)) && visit(t, lowerBound(s)); |
|
667 |
||
668 |
if (t.isCompound() && s.isCompound()) { |
|
669 |
if (!visit(supertype(t), supertype(s))) |
|
670 |
return false; |
|
671 |
||
672 |
HashSet<SingletonType> set = new HashSet<SingletonType>(); |
|
673 |
for (Type x : interfaces(t)) |
|
674 |
set.add(new SingletonType(x)); |
|
675 |
for (Type x : interfaces(s)) { |
|
676 |
if (!set.remove(new SingletonType(x))) |
|
677 |
return false; |
|
678 |
} |
|
7637 | 679 |
return (set.isEmpty()); |
10 | 680 |
} |
681 |
return t.tsym == s.tsym |
|
682 |
&& visit(t.getEnclosingType(), s.getEnclosingType()) |
|
683 |
&& containsTypeEquivalent(t.getTypeArguments(), s.getTypeArguments()); |
|
684 |
} |
|
685 |
||
686 |
@Override |
|
687 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
688 |
if (t == s) |
|
689 |
return true; |
|
690 |
||
691 |
if (s.tag >= firstPartialTag) |
|
692 |
return visit(s, t); |
|
693 |
||
694 |
return s.tag == ARRAY |
|
695 |
&& containsTypeEquivalent(t.elemtype, elemtype(s)); |
|
696 |
} |
|
697 |
||
698 |
@Override |
|
699 |
public Boolean visitMethodType(MethodType t, Type s) { |
|
700 |
// isSameType for methods does not take thrown |
|
701 |
// exceptions into account! |
|
702 |
return hasSameArgs(t, s) && visit(t.getReturnType(), s.getReturnType()); |
|
703 |
} |
|
704 |
||
705 |
@Override |
|
706 |
public Boolean visitPackageType(PackageType t, Type s) { |
|
707 |
return t == s; |
|
708 |
} |
|
709 |
||
710 |
@Override |
|
711 |
public Boolean visitForAll(ForAll t, Type s) { |
|
712 |
if (s.tag != FORALL) |
|
713 |
return false; |
|
714 |
||
715 |
ForAll forAll = (ForAll)s; |
|
716 |
return hasSameBounds(t, forAll) |
|
717 |
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars)); |
|
718 |
} |
|
719 |
||
720 |
@Override |
|
721 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
722 |
if (s.tag == WILDCARD) |
|
723 |
// FIXME, this might be leftovers from before capture conversion |
|
724 |
return false; |
|
725 |
||
726 |
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) |
|
727 |
return true; |
|
728 |
||
729 |
if (t.inst != null) |
|
730 |
return visit(t.inst, s); |
|
731 |
||
732 |
t.inst = fromUnknownFun.apply(s); |
|
733 |
for (List<Type> l = t.lobounds; l.nonEmpty(); l = l.tail) { |
|
734 |
if (!isSubtype(l.head, t.inst)) |
|
735 |
return false; |
|
736 |
} |
|
737 |
for (List<Type> l = t.hibounds; l.nonEmpty(); l = l.tail) { |
|
738 |
if (!isSubtype(t.inst, l.head)) |
|
739 |
return false; |
|
740 |
} |
|
741 |
return true; |
|
742 |
} |
|
743 |
||
744 |
@Override |
|
745 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
746 |
return true; |
|
747 |
} |
|
748 |
}; |
|
749 |
// </editor-fold> |
|
750 |
||
751 |
// <editor-fold defaultstate="collapsed" desc="fromUnknownFun"> |
|
752 |
/** |
|
753 |
* A mapping that turns all unknown types in this type to fresh |
|
754 |
* unknown variables. |
|
755 |
*/ |
|
756 |
public Mapping fromUnknownFun = new Mapping("fromUnknownFun") { |
|
757 |
public Type apply(Type t) { |
|
758 |
if (t.tag == UNKNOWN) return new UndetVar(t); |
|
759 |
else return t.map(this); |
|
760 |
} |
|
761 |
}; |
|
762 |
// </editor-fold> |
|
763 |
||
764 |
// <editor-fold defaultstate="collapsed" desc="Contains Type"> |
|
765 |
public boolean containedBy(Type t, Type s) { |
|
766 |
switch (t.tag) { |
|
767 |
case UNDETVAR: |
|
768 |
if (s.tag == WILDCARD) { |
|
769 |
UndetVar undetvar = (UndetVar)t; |
|
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
770 |
WildcardType wt = (WildcardType)s; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
771 |
switch(wt.kind) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
772 |
case UNBOUND: //similar to ? extends Object |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
773 |
case EXTENDS: { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
774 |
Type bound = upperBound(s); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
775 |
// We should check the new upper bound against any of the |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
776 |
// undetvar's lower bounds. |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
777 |
for (Type t2 : undetvar.lobounds) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
778 |
if (!isSubtype(t2, bound)) |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
779 |
return false; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
780 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
781 |
undetvar.hibounds = undetvar.hibounds.prepend(bound); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
782 |
break; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
783 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
784 |
case SUPER: { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
785 |
Type bound = lowerBound(s); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
786 |
// We should check the new lower bound against any of the |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
787 |
// undetvar's lower bounds. |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
788 |
for (Type t2 : undetvar.hibounds) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
789 |
if (!isSubtype(bound, t2)) |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
790 |
return false; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
791 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
792 |
undetvar.lobounds = undetvar.lobounds.prepend(bound); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
793 |
break; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
794 |
} |
1535
a64c289fe413
6762569: Javac crashes with AssertionError in Types.containedBy
mcimadamore
parents:
1530
diff
changeset
|
795 |
} |
10 | 796 |
return true; |
797 |
} else { |
|
798 |
return isSameType(t, s); |
|
799 |
} |
|
800 |
case ERROR: |
|
801 |
return true; |
|
802 |
default: |
|
803 |
return containsType(s, t); |
|
804 |
} |
|
805 |
} |
|
806 |
||
807 |
boolean containsType(List<Type> ts, List<Type> ss) { |
|
808 |
while (ts.nonEmpty() && ss.nonEmpty() |
|
809 |
&& containsType(ts.head, ss.head)) { |
|
810 |
ts = ts.tail; |
|
811 |
ss = ss.tail; |
|
812 |
} |
|
813 |
return ts.isEmpty() && ss.isEmpty(); |
|
814 |
} |
|
815 |
||
816 |
/** |
|
817 |
* Check if t contains s. |
|
818 |
* |
|
819 |
* <p>T contains S if: |
|
820 |
* |
|
821 |
* <p>{@code L(T) <: L(S) && U(S) <: U(T)} |
|
822 |
* |
|
823 |
* <p>This relation is only used by ClassType.isSubtype(), that |
|
824 |
* is, |
|
825 |
* |
|
826 |
* <p>{@code C<S> <: C<T> if T contains S.} |
|
827 |
* |
|
828 |
* <p>Because of F-bounds, this relation can lead to infinite |
|
829 |
* recursion. Thus we must somehow break that recursion. Notice |
|
830 |
* that containsType() is only called from ClassType.isSubtype(). |
|
831 |
* Since the arguments have already been checked against their |
|
832 |
* bounds, we know: |
|
833 |
* |
|
834 |
* <p>{@code U(S) <: U(T) if T is "super" bound (U(T) *is* the bound)} |
|
835 |
* |
|
836 |
* <p>{@code L(T) <: L(S) if T is "extends" bound (L(T) is bottom)} |
|
837 |
* |
|
838 |
* @param t a type |
|
839 |
* @param s a type |
|
840 |
*/ |
|
841 |
public boolean containsType(Type t, Type s) { |
|
842 |
return containsType.visit(t, s); |
|
843 |
} |
|
844 |
// where |
|
845 |
private TypeRelation containsType = new TypeRelation() { |
|
846 |
||
847 |
private Type U(Type t) { |
|
848 |
while (t.tag == WILDCARD) { |
|
849 |
WildcardType w = (WildcardType)t; |
|
850 |
if (w.isSuperBound()) |
|
851 |
return w.bound == null ? syms.objectType : w.bound.bound; |
|
852 |
else |
|
853 |
t = w.type; |
|
854 |
} |
|
855 |
return t; |
|
856 |
} |
|
857 |
||
858 |
private Type L(Type t) { |
|
859 |
while (t.tag == WILDCARD) { |
|
860 |
WildcardType w = (WildcardType)t; |
|
861 |
if (w.isExtendsBound()) |
|
862 |
return syms.botType; |
|
863 |
else |
|
864 |
t = w.type; |
|
865 |
} |
|
866 |
return t; |
|
867 |
} |
|
868 |
||
869 |
public Boolean visitType(Type t, Type s) { |
|
870 |
if (s.tag >= firstPartialTag) |
|
871 |
return containedBy(s, t); |
|
872 |
else |
|
873 |
return isSameType(t, s); |
|
874 |
} |
|
875 |
||
7637 | 876 |
// void debugContainsType(WildcardType t, Type s) { |
877 |
// System.err.println(); |
|
878 |
// System.err.format(" does %s contain %s?%n", t, s); |
|
879 |
// System.err.format(" %s U(%s) <: U(%s) %s = %s%n", |
|
880 |
// upperBound(s), s, t, U(t), |
|
881 |
// t.isSuperBound() |
|
882 |
// || isSubtypeNoCapture(upperBound(s), U(t))); |
|
883 |
// System.err.format(" %s L(%s) <: L(%s) %s = %s%n", |
|
884 |
// L(t), t, s, lowerBound(s), |
|
885 |
// t.isExtendsBound() |
|
886 |
// || isSubtypeNoCapture(L(t), lowerBound(s))); |
|
887 |
// System.err.println(); |
|
888 |
// } |
|
10 | 889 |
|
890 |
@Override |
|
891 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
892 |
if (s.tag >= firstPartialTag) |
|
893 |
return containedBy(s, t); |
|
894 |
else { |
|
7637 | 895 |
// debugContainsType(t, s); |
10 | 896 |
return isSameWildcard(t, s) |
897 |
|| isCaptureOf(s, t) |
|
898 |
|| ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) && |
|
899 |
(t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t)))); |
|
900 |
} |
|
901 |
} |
|
902 |
||
903 |
@Override |
|
904 |
public Boolean visitUndetVar(UndetVar t, Type s) { |
|
905 |
if (s.tag != WILDCARD) |
|
906 |
return isSameType(t, s); |
|
907 |
else |
|
908 |
return false; |
|
909 |
} |
|
910 |
||
911 |
@Override |
|
912 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
913 |
return true; |
|
914 |
} |
|
915 |
}; |
|
916 |
||
917 |
public boolean isCaptureOf(Type s, WildcardType t) { |
|
938
13aae74ca013
6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents:
735
diff
changeset
|
918 |
if (s.tag != TYPEVAR || !((TypeVar)s).isCaptured()) |
10 | 919 |
return false; |
920 |
return isSameWildcard(t, ((CapturedType)s).wildcard); |
|
921 |
} |
|
922 |
||
923 |
public boolean isSameWildcard(WildcardType t, Type s) { |
|
924 |
if (s.tag != WILDCARD) |
|
925 |
return false; |
|
926 |
WildcardType w = (WildcardType)s; |
|
927 |
return w.kind == t.kind && w.type == t.type; |
|
928 |
} |
|
929 |
||
930 |
public boolean containsTypeEquivalent(List<Type> ts, List<Type> ss) { |
|
931 |
while (ts.nonEmpty() && ss.nonEmpty() |
|
932 |
&& containsTypeEquivalent(ts.head, ss.head)) { |
|
933 |
ts = ts.tail; |
|
934 |
ss = ss.tail; |
|
935 |
} |
|
936 |
return ts.isEmpty() && ss.isEmpty(); |
|
937 |
} |
|
938 |
// </editor-fold> |
|
939 |
||
940 |
// <editor-fold defaultstate="collapsed" desc="isCastable"> |
|
941 |
public boolean isCastable(Type t, Type s) { |
|
942 |
return isCastable(t, s, Warner.noWarnings); |
|
943 |
} |
|
944 |
||
945 |
/** |
|
946 |
* Is t is castable to s?<br> |
|
947 |
* s is assumed to be an erased type.<br> |
|
948 |
* (not defined for Method and ForAll types). |
|
949 |
*/ |
|
950 |
public boolean isCastable(Type t, Type s, Warner warn) { |
|
951 |
if (t == s) |
|
952 |
return true; |
|
953 |
||
954 |
if (t.isPrimitive() != s.isPrimitive()) |
|
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
955 |
return allowBoxing && ( |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
956 |
isConvertible(t, s, warn) |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
957 |
|| (allowObjectToPrimitiveCast && isConvertible(s, t, warn))); |
10 | 958 |
if (warn != warnStack.head) { |
959 |
try { |
|
960 |
warnStack = warnStack.prepend(warn); |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
961 |
checkUnsafeVarargsConversion(t, s, warn); |
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
962 |
return isCastable.visit(t,s); |
10 | 963 |
} finally { |
964 |
warnStack = warnStack.tail; |
|
965 |
} |
|
966 |
} else { |
|
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
967 |
return isCastable.visit(t,s); |
10 | 968 |
} |
969 |
} |
|
970 |
// where |
|
971 |
private TypeRelation isCastable = new TypeRelation() { |
|
972 |
||
973 |
public Boolean visitType(Type t, Type s) { |
|
974 |
if (s.tag == ERROR) |
|
975 |
return true; |
|
976 |
||
977 |
switch (t.tag) { |
|
978 |
case BYTE: case CHAR: case SHORT: case INT: case LONG: case FLOAT: |
|
979 |
case DOUBLE: |
|
980 |
return s.tag <= DOUBLE; |
|
981 |
case BOOLEAN: |
|
982 |
return s.tag == BOOLEAN; |
|
983 |
case VOID: |
|
984 |
return false; |
|
985 |
case BOT: |
|
986 |
return isSubtype(t, s); |
|
987 |
default: |
|
988 |
throw new AssertionError(); |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
@Override |
|
993 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
994 |
return isCastable(upperBound(t), s, warnStack.head); |
|
995 |
} |
|
996 |
||
997 |
@Override |
|
998 |
public Boolean visitClassType(ClassType t, Type s) { |
|
999 |
if (s.tag == ERROR || s.tag == BOT) |
|
1000 |
return true; |
|
1001 |
||
1002 |
if (s.tag == TYPEVAR) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1003 |
if (isCastable(t, s.getUpperBound(), Warner.noWarnings)) { |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1004 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1005 |
return true; |
1006 |
} else { |
|
1007 |
return false; |
|
1008 |
} |
|
1009 |
} |
|
1010 |
||
1011 |
if (t.isCompound()) { |
|
1992
7be5dee022d5
6557182: Unchecked warning *and* inconvertible types
mcimadamore
parents:
1991
diff
changeset
|
1012 |
Warner oldWarner = warnStack.head; |
7be5dee022d5
6557182: Unchecked warning *and* inconvertible types
mcimadamore
parents:
1991
diff
changeset
|
1013 |
warnStack.head = Warner.noWarnings; |
10 | 1014 |
if (!visit(supertype(t), s)) |
1015 |
return false; |
|
1016 |
for (Type intf : interfaces(t)) { |
|
1017 |
if (!visit(intf, s)) |
|
1018 |
return false; |
|
1019 |
} |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1020 |
if (warnStack.head.hasLint(LintCategory.UNCHECKED)) |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1021 |
oldWarner.warn(LintCategory.UNCHECKED); |
10 | 1022 |
return true; |
1023 |
} |
|
1024 |
||
1025 |
if (s.isCompound()) { |
|
1026 |
// call recursively to reuse the above code |
|
1027 |
return visitClassType((ClassType)s, t); |
|
1028 |
} |
|
1029 |
||
1030 |
if (s.tag == CLASS || s.tag == ARRAY) { |
|
1031 |
boolean upcast; |
|
1032 |
if ((upcast = isSubtype(erasure(t), erasure(s))) |
|
1033 |
|| isSubtype(erasure(s), erasure(t))) { |
|
1034 |
if (!upcast && s.tag == ARRAY) { |
|
1035 |
if (!isReifiable(s)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1036 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1037 |
return true; |
1038 |
} else if (s.isRaw()) { |
|
1039 |
return true; |
|
1040 |
} else if (t.isRaw()) { |
|
1041 |
if (!isUnbounded(s)) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1042 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1043 |
return true; |
1044 |
} |
|
1045 |
// Assume |a| <: |b| |
|
1046 |
final Type a = upcast ? t : s; |
|
1047 |
final Type b = upcast ? s : t; |
|
1048 |
final boolean HIGH = true; |
|
1049 |
final boolean LOW = false; |
|
1050 |
final boolean DONT_REWRITE_TYPEVARS = false; |
|
1051 |
Type aHigh = rewriteQuantifiers(a, HIGH, DONT_REWRITE_TYPEVARS); |
|
1052 |
Type aLow = rewriteQuantifiers(a, LOW, DONT_REWRITE_TYPEVARS); |
|
1053 |
Type bHigh = rewriteQuantifiers(b, HIGH, DONT_REWRITE_TYPEVARS); |
|
1054 |
Type bLow = rewriteQuantifiers(b, LOW, DONT_REWRITE_TYPEVARS); |
|
1055 |
Type lowSub = asSub(bLow, aLow.tsym); |
|
1056 |
Type highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym); |
|
1057 |
if (highSub == null) { |
|
1058 |
final boolean REWRITE_TYPEVARS = true; |
|
1059 |
aHigh = rewriteQuantifiers(a, HIGH, REWRITE_TYPEVARS); |
|
1060 |
aLow = rewriteQuantifiers(a, LOW, REWRITE_TYPEVARS); |
|
1061 |
bHigh = rewriteQuantifiers(b, HIGH, REWRITE_TYPEVARS); |
|
1062 |
bLow = rewriteQuantifiers(b, LOW, REWRITE_TYPEVARS); |
|
1063 |
lowSub = asSub(bLow, aLow.tsym); |
|
1064 |
highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym); |
|
1065 |
} |
|
1066 |
if (highSub != null) { |
|
8032 | 1067 |
if (!(a.tsym == highSub.tsym && a.tsym == lowSub.tsym)) { |
1068 |
Assert.error(a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym); |
|
1069 |
} |
|
1790
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1070 |
if (!disjointTypes(aHigh.allparams(), highSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1071 |
&& !disjointTypes(aHigh.allparams(), lowSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1072 |
&& !disjointTypes(aLow.allparams(), highSub.allparams()) |
7182011ee8a6
6665356: Cast not allowed when both qualifying type and inner class are parameterized
mcimadamore
parents:
1535
diff
changeset
|
1073 |
&& !disjointTypes(aLow.allparams(), lowSub.allparams())) { |
7627
de2a86da165e
7005095: Cast: compile reject sensible cast from final class to interface
mcimadamore
parents:
7331
diff
changeset
|
1074 |
if (upcast ? giveWarning(a, b) : |
2218
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
1075 |
giveWarning(b, a)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1076 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1077 |
return true; |
1078 |
} |
|
1079 |
} |
|
1080 |
if (isReifiable(s)) |
|
1081 |
return isSubtypeUnchecked(a, b); |
|
1082 |
else |
|
1083 |
return isSubtypeUnchecked(a, b, warnStack.head); |
|
1084 |
} |
|
1085 |
||
1086 |
// Sidecast |
|
1087 |
if (s.tag == CLASS) { |
|
1088 |
if ((s.tsym.flags() & INTERFACE) != 0) { |
|
1089 |
return ((t.tsym.flags() & FINAL) == 0) |
|
1090 |
? sideCast(t, s, warnStack.head) |
|
1091 |
: sideCastFinal(t, s, warnStack.head); |
|
1092 |
} else if ((t.tsym.flags() & INTERFACE) != 0) { |
|
1093 |
return ((s.tsym.flags() & FINAL) == 0) |
|
1094 |
? sideCast(t, s, warnStack.head) |
|
1095 |
: sideCastFinal(t, s, warnStack.head); |
|
1096 |
} else { |
|
1097 |
// unrelated class types |
|
1098 |
return false; |
|
1099 |
} |
|
1100 |
} |
|
1101 |
} |
|
1102 |
return false; |
|
1103 |
} |
|
1104 |
||
1105 |
@Override |
|
1106 |
public Boolean visitArrayType(ArrayType t, Type s) { |
|
1107 |
switch (s.tag) { |
|
1108 |
case ERROR: |
|
1109 |
case BOT: |
|
1110 |
return true; |
|
1111 |
case TYPEVAR: |
|
1112 |
if (isCastable(s, t, Warner.noWarnings)) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1113 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1114 |
return true; |
1115 |
} else { |
|
1116 |
return false; |
|
1117 |
} |
|
1118 |
case CLASS: |
|
1119 |
return isSubtype(t, s); |
|
1120 |
case ARRAY: |
|
7634
00834a375696
7005671: Regression: compiler accepts invalid cast from X[] to primitive array
mcimadamore
parents:
7628
diff
changeset
|
1121 |
if (elemtype(t).tag <= lastBaseTag || |
00834a375696
7005671: Regression: compiler accepts invalid cast from X[] to primitive array
mcimadamore
parents:
7628
diff
changeset
|
1122 |
elemtype(s).tag <= lastBaseTag) { |
10 | 1123 |
return elemtype(t).tag == elemtype(s).tag; |
1124 |
} else { |
|
1125 |
return visit(elemtype(t), elemtype(s)); |
|
1126 |
} |
|
1127 |
default: |
|
1128 |
return false; |
|
1129 |
} |
|
1130 |
} |
|
1131 |
||
1132 |
@Override |
|
1133 |
public Boolean visitTypeVar(TypeVar t, Type s) { |
|
1134 |
switch (s.tag) { |
|
1135 |
case ERROR: |
|
1136 |
case BOT: |
|
1137 |
return true; |
|
1138 |
case TYPEVAR: |
|
1139 |
if (isSubtype(t, s)) { |
|
1140 |
return true; |
|
1141 |
} else if (isCastable(t.bound, s, Warner.noWarnings)) { |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
1142 |
warnStack.head.warn(LintCategory.UNCHECKED); |
10 | 1143 |
return true; |
1144 |
} else { |
|
1145 |
return false; |
|
1146 |
} |
|
1147 |
default: |
|
1148 |
return isCastable(t.bound, s, warnStack.head); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
||
1152 |
@Override |
|
1153 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
1154 |
return true; |
|
1155 |
} |
|
1156 |
}; |
|
1157 |
// </editor-fold> |
|
1158 |
||
1159 |
// <editor-fold defaultstate="collapsed" desc="disjointTypes"> |
|
1160 |
public boolean disjointTypes(List<Type> ts, List<Type> ss) { |
|
1161 |
while (ts.tail != null && ss.tail != null) { |
|
1162 |
if (disjointType(ts.head, ss.head)) return true; |
|
1163 |
ts = ts.tail; |
|
1164 |
ss = ss.tail; |
|
1165 |
} |
|
1166 |
return false; |
|
1167 |
} |
|
1168 |
||
1169 |
/** |
|
1170 |
* Two types or wildcards are considered disjoint if it can be |
|
1171 |
* proven that no type can be contained in both. It is |
|
1172 |
* conservative in that it is allowed to say that two types are |
|
1173 |
* not disjoint, even though they actually are. |
|
1174 |
* |
|
1175 |
* The type C<X> is castable to C<Y> exactly if X and Y are not |
|
1176 |
* disjoint. |
|
1177 |
*/ |
|
1178 |
public boolean disjointType(Type t, Type s) { |
|
1179 |
return disjointType.visit(t, s); |
|
1180 |
} |
|
1181 |
// where |
|
1182 |
private TypeRelation disjointType = new TypeRelation() { |
|
1183 |
||
1184 |
private Set<TypePair> cache = new HashSet<TypePair>(); |
|
1185 |
||
1186 |
public Boolean visitType(Type t, Type s) { |
|
1187 |
if (s.tag == WILDCARD) |
|
1188 |
return visit(s, t); |
|
1189 |
else |
|
1190 |
return notSoftSubtypeRecursive(t, s) || notSoftSubtypeRecursive(s, t); |
|
1191 |
} |
|
1192 |
||
1193 |
private boolean isCastableRecursive(Type t, Type s) { |
|
1194 |
TypePair pair = new TypePair(t, s); |
|
1195 |
if (cache.add(pair)) { |
|
1196 |
try { |
|
1197 |
return Types.this.isCastable(t, s); |
|
1198 |
} finally { |
|
1199 |
cache.remove(pair); |
|
1200 |
} |
|
1201 |
} else { |
|
1202 |
return true; |
|
1203 |
} |
|
1204 |
} |
|
1205 |
||
1206 |
private boolean notSoftSubtypeRecursive(Type t, Type s) { |
|
1207 |
TypePair pair = new TypePair(t, s); |
|
1208 |
if (cache.add(pair)) { |
|
1209 |
try { |
|
1210 |
return Types.this.notSoftSubtype(t, s); |
|
1211 |
} finally { |
|
1212 |
cache.remove(pair); |
|
1213 |
} |
|
1214 |
} else { |
|
1215 |
return false; |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
@Override |
|
1220 |
public Boolean visitWildcardType(WildcardType t, Type s) { |
|
1221 |
if (t.isUnbound()) |
|
1222 |
return false; |
|
1223 |
||
1224 |
if (s.tag != WILDCARD) { |
|
1225 |
if (t.isExtendsBound()) |
|
1226 |
return notSoftSubtypeRecursive(s, t.type); |
|
1227 |
else // isSuperBound() |
|
1228 |
return notSoftSubtypeRecursive(t.type, s); |
|
1229 |
} |
|
1230 |
||
1231 |
if (s.isUnbound()) |
|
1232 |
return false; |
|
1233 |
||
1234 |
if (t.isExtendsBound()) { |
|
1235 |
if (s.isExtendsBound()) |
|
1236 |
return !isCastableRecursive(t.type, upperBound(s)); |
|
1237 |
else if (s.isSuperBound()) |
|
1238 |
return notSoftSubtypeRecursive(lowerBound(s), t.type); |
|
1239 |
} else if (t.isSuperBound()) { |
|
1240 |
if (s.isExtendsBound()) |
|
1241 |
return notSoftSubtypeRecursive(t.type, upperBound(s)); |
|
1242 |
} |
|
1243 |
return false; |
|
1244 |
} |
|
1245 |
}; |
|
1246 |
// </editor-fold> |
|
1247 |
||
1248 |
// <editor-fold defaultstate="collapsed" desc="lowerBoundArgtypes"> |
|
1249 |
/** |
|
1250 |
* Returns the lower bounds of the formals of a method. |
|
1251 |
*/ |
|
1252 |
public List<Type> lowerBoundArgtypes(Type t) { |
|
1253 |
return map(t.getParameterTypes(), lowerBoundMapping); |
|
1254 |
} |
|
1255 |
private final Mapping lowerBoundMapping = new Mapping("lowerBound") { |
|
1256 |
public Type apply(Type t) { |
|
1257 |
return lowerBound(t); |
|
1258 |
} |
|
1259 |
}; |
|
1260 |
// </editor-fold> |
|
1261 |
||
1262 |
// <editor-fold defaultstate="collapsed" desc="notSoftSubtype"> |
|
1263 |
/** |
|
1264 |
* This relation answers the question: is impossible that |
|
1265 |
* something of type `t' can be a subtype of `s'? This is |
|
1266 |
* different from the question "is `t' not a subtype of `s'?" |
|
1267 |
* when type variables are involved: Integer is not a subtype of T |
|
1268 |
* where <T extends Number> but it is not true that Integer cannot |
|
1269 |
* possibly be a subtype of T. |
|
1270 |
*/ |
|
1271 |
public boolean notSoftSubtype(Type t, Type s) { |
|
1272 |
if (t == s) return false; |
|
1273 |
if (t.tag == TYPEVAR) { |
|
1274 |
TypeVar tv = (TypeVar) t; |
|
1275 |
return !isCastable(tv.bound, |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1276 |
relaxBound(s), |
10 | 1277 |
Warner.noWarnings); |
1278 |
} |
|
1279 |
if (s.tag != WILDCARD) |
|
1280 |
s = upperBound(s); |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1281 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1282 |
return !isSubtype(t, relaxBound(s)); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1283 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1284 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1285 |
private Type relaxBound(Type t) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1286 |
if (t.tag == TYPEVAR) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1287 |
while (t.tag == TYPEVAR) |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1288 |
t = t.getUpperBound(); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1289 |
t = rewriteQuantifiers(t, true, true); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1290 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
1291 |
return t; |
10 | 1292 |
} |
1293 |
// </editor-fold> |
|
1294 |
||
1295 |
// <editor-fold defaultstate="collapsed" desc="isReifiable"> |
|
1296 |
public boolean isReifiable(Type t) { |
|
1297 |
return isReifiable.visit(t); |
|
1298 |
} |
|
1299 |
// where |
|
1300 |
private UnaryVisitor<Boolean> isReifiable = new UnaryVisitor<Boolean>() { |
|
1301 |
||
1302 |
public Boolean visitType(Type t, Void ignored) { |
|
1303 |
return true; |
|
1304 |
} |
|
1305 |
||
1306 |
@Override |
|
1307 |
public Boolean visitClassType(ClassType t, Void ignored) { |
|
3554
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1308 |
if (t.isCompound()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1309 |
return false; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1310 |
else { |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1311 |
if (!t.isParameterized()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1312 |
return true; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1313 |
|
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1314 |
for (Type param : t.allparams()) { |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1315 |
if (!param.isUnbound()) |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1316 |
return false; |
a0a7f7f2a6e5
6806876: ClassCastException occurs in assignment expressions without any heap pollutions
mcimadamore
parents:
3539
diff
changeset
|
1317 |
} |
10 | 1318 |
return true; |
1319 |
} |
|
1320 |
} |
|
1321 |
||
1322 |
@Override |
|
1323 |
public Boolean visitArrayType(ArrayType t, Void ignored) { |
|
1324 |
return visit(t.elemtype); |
|
1325 |
} |
|
1326 |
||
1327 |
@Override |
|
1328 |
public Boolean visitTypeVar(TypeVar t, Void ignored) { |
|
1329 |
return false; |
|
1330 |
} |
|
1331 |
}; |
|
1332 |
// </editor-fold> |
|
1333 |
||
1334 |
// <editor-fold defaultstate="collapsed" desc="Array Utils"> |
|
1335 |
public boolean isArray(Type t) { |
|
1336 |
while (t.tag == WILDCARD) |
|
1337 |
t = upperBound(t); |
|
1338 |
return t.tag == ARRAY; |
|
1339 |
} |
|
1340 |
||
1341 |
/** |
|
1342 |
* The element type of an array. |
|
1343 |
*/ |
|
1344 |
public Type elemtype(Type t) { |
|
1345 |
switch (t.tag) { |
|
1346 |
case WILDCARD: |
|
1347 |
return elemtype(upperBound(t)); |
|
1348 |
case ARRAY: |
|
1349 |
return ((ArrayType)t).elemtype; |
|
1350 |
case FORALL: |
|
1351 |
return elemtype(((ForAll)t).qtype); |
|
1352 |
case ERROR: |
|
1353 |
return t; |
|
1354 |
default: |
|
1355 |
return null; |
|
1356 |
} |
|
1357 |
} |
|
1358 |
||
7635
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1359 |
public Type elemtypeOrType(Type t) { |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1360 |
Type elemtype = elemtype(t); |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1361 |
return elemtype != null ? |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1362 |
elemtype : |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1363 |
t; |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1364 |
} |
e0a3aeefe4e7
6199075: Unambiguous varargs method calls flagged as ambiguous
mcimadamore
parents:
7634
diff
changeset
|
1365 |
|
10 | 1366 |
/** |
1367 |
* Mapping to take element type of an arraytype |
|
1368 |
*/ |
|
1369 |
private Mapping elemTypeFun = new Mapping ("elemTypeFun") { |
|
1370 |
public Type apply(Type t) { return elemtype(t); } |
|
1371 |
}; |
|
1372 |
||
1373 |
/** |
|
1374 |
* The number of dimensions of an array type. |
|
1375 |
*/ |
|
1376 |
public int dimensions(Type t) { |
|
1377 |
int result = 0; |
|
1378 |
while (t.tag == ARRAY) { |
|
1379 |
result++; |
|
1380 |
t = elemtype(t); |
|
1381 |
} |
|
1382 |
return result; |
|
1383 |
} |
|
1384 |
// </editor-fold> |
|
1385 |
||
1386 |
// <editor-fold defaultstate="collapsed" desc="asSuper"> |
|
1387 |
/** |
|
1388 |
* Return the (most specific) base type of t that starts with the |
|
1389 |
* given symbol. If none exists, return null. |
|
1390 |
* |
|
1391 |
* @param t a type |
|
1392 |
* @param sym a symbol |
|
1393 |
*/ |
|
1394 |
public Type asSuper(Type t, Symbol sym) { |
|
1395 |
return asSuper.visit(t, sym); |
|
1396 |
} |
|
1397 |
// where |
|
1398 |
private SimpleVisitor<Type,Symbol> asSuper = new SimpleVisitor<Type,Symbol>() { |
|
1399 |
||
1400 |
public Type visitType(Type t, Symbol sym) { |
|
1401 |
return null; |
|
1402 |
} |
|
1403 |
||
1404 |
@Override |
|
1405 |
public Type visitClassType(ClassType t, Symbol sym) { |
|
1406 |
if (t.tsym == sym) |
|
1407 |
return t; |
|
1408 |
||
1409 |
Type st = supertype(t); |
|
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
1410 |
if (st.tag == CLASS || st.tag == TYPEVAR || st.tag == ERROR) { |
10 | 1411 |
Type x = asSuper(st, sym); |
1412 |
if (x != null) |
|
1413 |
return x; |
|
1414 |
} |
|
1415 |
if ((sym.flags() & INTERFACE) != 0) { |
|
1416 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |
|
1417 |
Type x = asSuper(l.head, sym); |
|
1418 |
if (x != null) |
|
1419 |
return x; |
|
1420 |
} |
|
1421 |
} |
|
1422 |
return null; |
|
1423 |
} |
|
1424 |
||
1425 |
@Override |
|
1426 |
public Type visitArrayType(ArrayType t, Symbol sym) { |
|
1427 |
return isSubtype(t, sym.type) ? sym.type : null; |
|
1428 |
} |
|
1429 |
||
1430 |
@Override |
|
1431 |
public Type visitTypeVar(TypeVar t, Symbol sym) { |
|
326
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
1432 |
if (t.tsym == sym) |
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
1433 |
return t; |
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
1434 |
else |
d51f30ce6796
6531090: Cannot access methods/fields of a captured type belonging to an intersection type
mcimadamore
parents:
162
diff
changeset
|
1435 |
return asSuper(t.bound, sym); |
10 | 1436 |
} |
1437 |
||
1438 |
@Override |
|
1439 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
|
1440 |
return t; |
|
1441 |
} |
|
1442 |
}; |
|
1443 |
||
1444 |
/** |
|
1445 |
* Return the base type of t or any of its outer types that starts |
|
1446 |
* with the given symbol. If none exists, return null. |
|
1447 |
* |
|
1448 |
* @param t a type |
|
1449 |
* @param sym a symbol |
|
1450 |
*/ |
|
1451 |
public Type asOuterSuper(Type t, Symbol sym) { |
|
1452 |
switch (t.tag) { |
|
1453 |
case CLASS: |
|
1454 |
do { |
|
1455 |
Type s = asSuper(t, sym); |
|
1456 |
if (s != null) return s; |
|
1457 |
t = t.getEnclosingType(); |
|
1458 |
} while (t.tag == CLASS); |
|
1459 |
return null; |
|
1460 |
case ARRAY: |
|
1461 |
return isSubtype(t, sym.type) ? sym.type : null; |
|
1462 |
case TYPEVAR: |
|
1463 |
return asSuper(t, sym); |
|
1464 |
case ERROR: |
|
1465 |
return t; |
|
1466 |
default: |
|
1467 |
return null; |
|
1468 |
} |
|
1469 |
} |
|
1470 |
||
1471 |
/** |
|
1472 |
* Return the base type of t or any of its enclosing types that |
|
1473 |
* starts with the given symbol. If none exists, return null. |
|
1474 |
* |
|
1475 |
* @param t a type |
|
1476 |
* @param sym a symbol |
|
1477 |
*/ |
|
1478 |
public Type asEnclosingSuper(Type t, Symbol sym) { |
|
1479 |
switch (t.tag) { |
|
1480 |
case CLASS: |
|
1481 |
do { |
|
1482 |
Type s = asSuper(t, sym); |
|
1483 |
if (s != null) return s; |
|
1484 |
Type outer = t.getEnclosingType(); |
|
1485 |
t = (outer.tag == CLASS) ? outer : |
|
1486 |
(t.tsym.owner.enclClass() != null) ? t.tsym.owner.enclClass().type : |
|
1487 |
Type.noType; |
|
1488 |
} while (t.tag == CLASS); |
|
1489 |
return null; |
|
1490 |
case ARRAY: |
|
1491 |
return isSubtype(t, sym.type) ? sym.type : null; |
|
1492 |
case TYPEVAR: |
|
1493 |
return asSuper(t, sym); |
|
1494 |
case ERROR: |
|
1495 |
return t; |
|
1496 |
default: |
|
1497 |
return null; |
|
1498 |
} |
|
1499 |
} |
|
1500 |
// </editor-fold> |
|
1501 |
||
1502 |
// <editor-fold defaultstate="collapsed" desc="memberType"> |
|
1503 |
/** |
|
1504 |
* The type of given symbol, seen as a member of t. |
|
1505 |
* |
|
1506 |
* @param t a type |
|
1507 |
* @param sym a symbol |
|
1508 |
*/ |
|
1509 |
public Type memberType(Type t, Symbol sym) { |
|
1510 |
return (sym.flags() & STATIC) != 0 |
|
1511 |
? sym.type |
|
1512 |
: memberType.visit(t, sym); |
|
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
1513 |
} |
10 | 1514 |
// where |
1515 |
private SimpleVisitor<Type,Symbol> memberType = new SimpleVisitor<Type,Symbol>() { |
|
1516 |
||
1517 |
public Type visitType(Type t, Symbol sym) { |
|
1518 |
return sym.type; |
|
1519 |
} |
|
1520 |
||
1521 |
@Override |
|
1522 |
public Type visitWildcardType(WildcardType t, Symbol sym) { |
|
1523 |
return memberType(upperBound(t), sym); |
|
1524 |
} |
|
1525 |
||
1526 |
@Override |
|
1527 |
public Type visitClassType(ClassType t, Symbol sym) { |
|
1528 |
Symbol owner = sym.owner; |
|
1529 |
long flags = sym.flags(); |
|
1530 |
if (((flags & STATIC) == 0) && owner.type.isParameterized()) { |
|
1531 |
Type base = asOuterSuper(t, owner); |
|
1469
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
1532 |
//if t is an intersection type T = CT & I1 & I2 ... & In |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
1533 |
//its supertypes CT, I1, ... In might contain wildcards |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
1534 |
//so we need to go through capture conversion |
9c381121f301
6738538: javac crashes when using a type parameter as a covariant method return type
mcimadamore
parents:
1357
diff
changeset
|
1535 |
base = t.isCompound() ? capture(base) : base; |
10 | 1536 |
if (base != null) { |
1537 |
List<Type> ownerParams = owner.type.allparams(); |
|
1538 |
List<Type> baseParams = base.allparams(); |
|
1539 |
if (ownerParams.nonEmpty()) { |
|
1540 |
if (baseParams.isEmpty()) { |
|
1541 |
// then base is a raw type |
|
1542 |
return erasure(sym.type); |
|
1543 |
} else { |
|
1544 |
return subst(sym.type, ownerParams, baseParams); |
|
1545 |
} |
|
1546 |
} |
|
1547 |
} |
|
1548 |
} |
|
1549 |
return sym.type; |
|
1550 |
} |
|
1551 |
||
1552 |
@Override |
|
1553 |
public Type visitTypeVar(TypeVar t, Symbol sym) { |
|
1554 |
return memberType(t.bound, sym); |
|
1555 |
} |
|
1556 |
||
1557 |
@Override |
|
1558 |
public Type visitErrorType(ErrorType t, Symbol sym) { |
|
1559 |
return t; |
|
1560 |
} |
|
1561 |
}; |
|
1562 |
// </editor-fold> |
|
1563 |
||
1564 |
// <editor-fold defaultstate="collapsed" desc="isAssignable"> |
|
1565 |
public boolean isAssignable(Type t, Type s) { |
|
1566 |
return isAssignable(t, s, Warner.noWarnings); |
|
1567 |
} |
|
1568 |
||
1569 |
/** |
|
1570 |
* Is t assignable to s?<br> |
|
1571 |
* Equivalent to subtype except for constant values and raw |
|
1572 |
* types.<br> |
|
1573 |
* (not defined for Method and ForAll types) |
|
1574 |
*/ |
|
1575 |
public boolean isAssignable(Type t, Type s, Warner warn) { |
|
1576 |
if (t.tag == ERROR) |
|
1577 |
return true; |
|
1578 |
if (t.tag <= INT && t.constValue() != null) { |
|
1579 |
int value = ((Number)t.constValue()).intValue(); |
|
1580 |
switch (s.tag) { |
|
1581 |
case BYTE: |
|
1582 |
if (Byte.MIN_VALUE <= value && value <= Byte.MAX_VALUE) |
|
1583 |
return true; |
|
1584 |
break; |
|
1585 |
case CHAR: |
|
1586 |
if (Character.MIN_VALUE <= value && value <= Character.MAX_VALUE) |
|
1587 |
return true; |
|
1588 |
break; |
|
1589 |
case SHORT: |
|
1590 |
if (Short.MIN_VALUE <= value && value <= Short.MAX_VALUE) |
|
1591 |
return true; |
|
1592 |
break; |
|
1593 |
case INT: |
|
1594 |
return true; |
|
1595 |
case CLASS: |
|
1596 |
switch (unboxedType(s).tag) { |
|
1597 |
case BYTE: |
|
1598 |
case CHAR: |
|
1599 |
case SHORT: |
|
1600 |
return isAssignable(t, unboxedType(s), warn); |
|
1601 |
} |
|
1602 |
break; |
|
1603 |
} |
|
1604 |
} |
|
1605 |
return isConvertible(t, s, warn); |
|
1606 |
} |
|
1607 |
// </editor-fold> |
|
1608 |
||
1609 |
// <editor-fold defaultstate="collapsed" desc="erasure"> |
|
1610 |
/** |
|
1611 |
* The erasure of t {@code |t|} -- the type that results when all |
|
1612 |
* type parameters in t are deleted. |
|
1613 |
*/ |
|
1614 |
public Type erasure(Type t) { |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1615 |
return erasure(t, false); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1616 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1617 |
//where |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1618 |
private Type erasure(Type t, boolean recurse) { |
10 | 1619 |
if (t.tag <= lastBaseTag) |
1620 |
return t; /* fast special case */ |
|
1621 |
else |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1622 |
return erasure.visit(t, recurse); |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
1623 |
} |
10 | 1624 |
// where |
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1625 |
private SimpleVisitor<Type, Boolean> erasure = new SimpleVisitor<Type, Boolean>() { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1626 |
public Type visitType(Type t, Boolean recurse) { |
10 | 1627 |
if (t.tag <= lastBaseTag) |
1628 |
return t; /*fast special case*/ |
|
1629 |
else |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1630 |
return t.map(recurse ? erasureRecFun : erasureFun); |
10 | 1631 |
} |
1632 |
||
1633 |
@Override |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1634 |
public Type visitWildcardType(WildcardType t, Boolean recurse) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1635 |
return erasure(upperBound(t), recurse); |
10 | 1636 |
} |
1637 |
||
1638 |
@Override |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1639 |
public Type visitClassType(ClassType t, Boolean recurse) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1640 |
Type erased = t.tsym.erasure(Types.this); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1641 |
if (recurse) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1642 |
erased = new ErasedClassType(erased.getEnclosingType(),erased.tsym); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1643 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1644 |
return erased; |
10 | 1645 |
} |
1646 |
||
1647 |
@Override |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1648 |
public Type visitTypeVar(TypeVar t, Boolean recurse) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1649 |
return erasure(t.bound, recurse); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1650 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1651 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1652 |
@Override |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1653 |
public Type visitErrorType(ErrorType t, Boolean recurse) { |
10 | 1654 |
return t; |
1655 |
} |
|
1656 |
}; |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1657 |
|
10 | 1658 |
private Mapping erasureFun = new Mapping ("erasure") { |
1659 |
public Type apply(Type t) { return erasure(t); } |
|
1660 |
}; |
|
1661 |
||
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1662 |
private Mapping erasureRecFun = new Mapping ("erasureRecursive") { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1663 |
public Type apply(Type t) { return erasureRecursive(t); } |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1664 |
}; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1665 |
|
10 | 1666 |
public List<Type> erasure(List<Type> ts) { |
1667 |
return Type.map(ts, erasureFun); |
|
1668 |
} |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1669 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1670 |
public Type erasureRecursive(Type t) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1671 |
return erasure(t, true); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1672 |
} |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1673 |
|
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1674 |
public List<Type> erasureRecursive(List<Type> ts) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1675 |
return Type.map(ts, erasureRecFun); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1676 |
} |
10 | 1677 |
// </editor-fold> |
1678 |
||
1679 |
// <editor-fold defaultstate="collapsed" desc="makeCompoundType"> |
|
1680 |
/** |
|
1681 |
* Make a compound type from non-empty list of types |
|
1682 |
* |
|
1683 |
* @param bounds the types from which the compound type is formed |
|
1684 |
* @param supertype is objectType if all bounds are interfaces, |
|
1685 |
* null otherwise. |
|
1686 |
*/ |
|
1687 |
public Type makeCompoundType(List<Type> bounds, |
|
1688 |
Type supertype) { |
|
1689 |
ClassSymbol bc = |
|
1690 |
new ClassSymbol(ABSTRACT|PUBLIC|SYNTHETIC|COMPOUND|ACYCLIC, |
|
1691 |
Type.moreInfo |
|
1692 |
? names.fromString(bounds.toString()) |
|
1693 |
: names.empty, |
|
1694 |
syms.noSymbol); |
|
1695 |
if (bounds.head.tag == TYPEVAR) |
|
1696 |
// error condition, recover |
|
1357 | 1697 |
bc.erasure_field = syms.objectType; |
1698 |
else |
|
1699 |
bc.erasure_field = erasure(bounds.head); |
|
1700 |
bc.members_field = new Scope(bc); |
|
10 | 1701 |
ClassType bt = (ClassType)bc.type; |
1702 |
bt.allparams_field = List.nil(); |
|
1703 |
if (supertype != null) { |
|
1704 |
bt.supertype_field = supertype; |
|
1705 |
bt.interfaces_field = bounds; |
|
1706 |
} else { |
|
1707 |
bt.supertype_field = bounds.head; |
|
1708 |
bt.interfaces_field = bounds.tail; |
|
1709 |
} |
|
8032 | 1710 |
Assert.check(bt.supertype_field.tsym.completer != null |
1711 |
|| !bt.supertype_field.isInterface(), |
|
1712 |
bt.supertype_field); |
|
10 | 1713 |
return bt; |
1714 |
} |
|
1715 |
||
1716 |
/** |
|
1717 |
* Same as {@link #makeCompoundType(List,Type)}, except that the |
|
1718 |
* second parameter is computed directly. Note that this might |
|
1719 |
* cause a symbol completion. Hence, this version of |
|
1720 |
* makeCompoundType may not be called during a classfile read. |
|
1721 |
*/ |
|
1722 |
public Type makeCompoundType(List<Type> bounds) { |
|
1723 |
Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? |
|
1724 |
supertype(bounds.head) : null; |
|
1725 |
return makeCompoundType(bounds, supertype); |
|
1726 |
} |
|
1727 |
||
1728 |
/** |
|
1729 |
* A convenience wrapper for {@link #makeCompoundType(List)}; the |
|
1730 |
* arguments are converted to a list and passed to the other |
|
1731 |
* method. Note that this might cause a symbol completion. |
|
1732 |
* Hence, this version of makeCompoundType may not be called |
|
1733 |
* during a classfile read. |
|
1734 |
*/ |
|
1735 |
public Type makeCompoundType(Type bound1, Type bound2) { |
|
1736 |
return makeCompoundType(List.of(bound1, bound2)); |
|
1737 |
} |
|
1738 |
// </editor-fold> |
|
1739 |
||
1740 |
// <editor-fold defaultstate="collapsed" desc="supertype"> |
|
1741 |
public Type supertype(Type t) { |
|
1742 |
return supertype.visit(t); |
|
1743 |
} |
|
1744 |
// where |
|
1745 |
private UnaryVisitor<Type> supertype = new UnaryVisitor<Type>() { |
|
1746 |
||
1747 |
public Type visitType(Type t, Void ignored) { |
|
1748 |
// A note on wildcards: there is no good way to |
|
1749 |
// determine a supertype for a super bounded wildcard. |
|
1750 |
return null; |
|
1751 |
} |
|
1752 |
||
1753 |
@Override |
|
1754 |
public Type visitClassType(ClassType t, Void ignored) { |
|
1755 |
if (t.supertype_field == null) { |
|
1756 |
Type supertype = ((ClassSymbol)t.tsym).getSuperclass(); |
|
1757 |
// An interface has no superclass; its supertype is Object. |
|
1758 |
if (t.isInterface()) |
|
1759 |
supertype = ((ClassType)t.tsym.type).supertype_field; |
|
1760 |
if (t.supertype_field == null) { |
|
1761 |
List<Type> actuals = classBound(t).allparams(); |
|
1762 |
List<Type> formals = t.tsym.type.allparams(); |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1763 |
if (t.hasErasedSupertypes()) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1764 |
t.supertype_field = erasureRecursive(supertype); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1765 |
} else if (formals.nonEmpty()) { |
10 | 1766 |
t.supertype_field = subst(supertype, formals, actuals); |
1767 |
} |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1768 |
else { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1769 |
t.supertype_field = supertype; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1770 |
} |
10 | 1771 |
} |
1772 |
} |
|
1773 |
return t.supertype_field; |
|
1774 |
} |
|
1775 |
||
1776 |
/** |
|
1777 |
* The supertype is always a class type. If the type |
|
1778 |
* variable's bounds start with a class type, this is also |
|
1779 |
* the supertype. Otherwise, the supertype is |
|
1780 |
* java.lang.Object. |
|
1781 |
*/ |
|
1782 |
@Override |
|
1783 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
1784 |
if (t.bound.tag == TYPEVAR || |
|
1785 |
(!t.bound.isCompound() && !t.bound.isInterface())) { |
|
1786 |
return t.bound; |
|
1787 |
} else { |
|
1788 |
return supertype(t.bound); |
|
1789 |
} |
|
1790 |
} |
|
1791 |
||
1792 |
@Override |
|
1793 |
public Type visitArrayType(ArrayType t, Void ignored) { |
|
1794 |
if (t.elemtype.isPrimitive() || isSameType(t.elemtype, syms.objectType)) |
|
1795 |
return arraySuperType(); |
|
1796 |
else |
|
1797 |
return new ArrayType(supertype(t.elemtype), t.tsym); |
|
1798 |
} |
|
1799 |
||
1800 |
@Override |
|
1801 |
public Type visitErrorType(ErrorType t, Void ignored) { |
|
1802 |
return t; |
|
1803 |
} |
|
1804 |
}; |
|
1805 |
// </editor-fold> |
|
1806 |
||
1807 |
// <editor-fold defaultstate="collapsed" desc="interfaces"> |
|
1808 |
/** |
|
1809 |
* Return the interfaces implemented by this class. |
|
1810 |
*/ |
|
1811 |
public List<Type> interfaces(Type t) { |
|
1812 |
return interfaces.visit(t); |
|
1813 |
} |
|
1814 |
// where |
|
1815 |
private UnaryVisitor<List<Type>> interfaces = new UnaryVisitor<List<Type>>() { |
|
1816 |
||
1817 |
public List<Type> visitType(Type t, Void ignored) { |
|
1818 |
return List.nil(); |
|
1819 |
} |
|
1820 |
||
1821 |
@Override |
|
1822 |
public List<Type> visitClassType(ClassType t, Void ignored) { |
|
1823 |
if (t.interfaces_field == null) { |
|
1824 |
List<Type> interfaces = ((ClassSymbol)t.tsym).getInterfaces(); |
|
1825 |
if (t.interfaces_field == null) { |
|
1826 |
// If t.interfaces_field is null, then t must |
|
1827 |
// be a parameterized type (not to be confused |
|
1828 |
// with a generic type declaration). |
|
1829 |
// Terminology: |
|
1830 |
// Parameterized type: List<String> |
|
1831 |
// Generic type declaration: class List<E> { ... } |
|
1832 |
// So t corresponds to List<String> and |
|
1833 |
// t.tsym.type corresponds to List<E>. |
|
1834 |
// The reason t must be parameterized type is |
|
1835 |
// that completion will happen as a side |
|
1836 |
// effect of calling |
|
1837 |
// ClassSymbol.getInterfaces. Since |
|
1838 |
// t.interfaces_field is null after |
|
1839 |
// completion, we can assume that t is not the |
|
1840 |
// type of a class/interface declaration. |
|
8032 | 1841 |
Assert.check(t != t.tsym.type, t); |
10 | 1842 |
List<Type> actuals = t.allparams(); |
1843 |
List<Type> formals = t.tsym.type.allparams(); |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1844 |
if (t.hasErasedSupertypes()) { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1845 |
t.interfaces_field = erasureRecursive(interfaces); |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1846 |
} else if (formals.nonEmpty()) { |
10 | 1847 |
t.interfaces_field = |
1848 |
upperBounds(subst(interfaces, formals, actuals)); |
|
1849 |
} |
|
514
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1850 |
else { |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1851 |
t.interfaces_field = interfaces; |
3942d9cdc81c
6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents:
326
diff
changeset
|
1852 |
} |
10 | 1853 |
} |
1854 |
} |
|
1855 |
return t.interfaces_field; |
|
1856 |
} |
|
1857 |
||
1858 |
@Override |
|
1859 |
public List<Type> visitTypeVar(TypeVar t, Void ignored) { |
|
1860 |
if (t.bound.isCompound()) |
|
1861 |
return interfaces(t.bound); |
|
1862 |
||
1863 |
if (t.bound.isInterface()) |
|
1864 |
return List.of(t.bound); |
|
1865 |
||
1866 |
return List.nil(); |
|
1867 |
} |
|
1868 |
}; |
|
1869 |
// </editor-fold> |
|
1870 |
||
1871 |
// <editor-fold defaultstate="collapsed" desc="isDerivedRaw"> |
|
1872 |
Map<Type,Boolean> isDerivedRawCache = new HashMap<Type,Boolean>(); |
|
1873 |
||
1874 |
public boolean isDerivedRaw(Type t) { |
|
1875 |
Boolean result = isDerivedRawCache.get(t); |
|
1876 |
if (result == null) { |
|
1877 |
result = isDerivedRawInternal(t); |
|
1878 |
isDerivedRawCache.put(t, result); |
|
1879 |
} |
|
1880 |
return result; |
|
1881 |
} |
|
1882 |
||
1883 |
public boolean isDerivedRawInternal(Type t) { |
|
1884 |
if (t.isErroneous()) |
|
1885 |
return false; |
|
1886 |
return |
|
1887 |
t.isRaw() || |
|
1888 |
supertype(t) != null && isDerivedRaw(supertype(t)) || |
|
1889 |
isDerivedRaw(interfaces(t)); |
|
1890 |
} |
|
1891 |
||
1892 |
public boolean isDerivedRaw(List<Type> ts) { |
|
1893 |
List<Type> l = ts; |
|
1894 |
while (l.nonEmpty() && !isDerivedRaw(l.head)) l = l.tail; |
|
1895 |
return l.nonEmpty(); |
|
1896 |
} |
|
1897 |
// </editor-fold> |
|
1898 |
||
1899 |
// <editor-fold defaultstate="collapsed" desc="setBounds"> |
|
1900 |
/** |
|
1901 |
* Set the bounds field of the given type variable to reflect a |
|
1902 |
* (possibly multiple) list of bounds. |
|
1903 |
* @param t a type variable |
|
1904 |
* @param bounds the bounds, must be nonempty |
|
1905 |
* @param supertype is objectType if all bounds are interfaces, |
|
1906 |
* null otherwise. |
|
1907 |
*/ |
|
1908 |
public void setBounds(TypeVar t, List<Type> bounds, Type supertype) { |
|
1909 |
if (bounds.tail.isEmpty()) |
|
1910 |
t.bound = bounds.head; |
|
1911 |
else |
|
1912 |
t.bound = makeCompoundType(bounds, supertype); |
|
1913 |
t.rank_field = -1; |
|
1914 |
} |
|
1915 |
||
1916 |
/** |
|
1917 |
* Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that |
|
5650
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1918 |
* third parameter is computed directly, as follows: if all |
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1919 |
* all bounds are interface types, the computed supertype is Object, |
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1920 |
* otherwise the supertype is simply left null (in this case, the supertype |
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1921 |
* is assumed to be the head of the bound list passed as second argument). |
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1922 |
* Note that this check might cause a symbol completion. Hence, this version of |
10 | 1923 |
* setBounds may not be called during a classfile read. |
1924 |
*/ |
|
1925 |
public void setBounds(TypeVar t, List<Type> bounds) { |
|
1926 |
Type supertype = (bounds.head.tsym.flags() & INTERFACE) != 0 ? |
|
5650
313b819dbcc2
6948381: javac Null Pointer Exception in Types.makeCompoundType
mcimadamore
parents:
5648
diff
changeset
|
1927 |
syms.objectType : null; |
10 | 1928 |
setBounds(t, bounds, supertype); |
1929 |
t.rank_field = -1; |
|
1930 |
} |
|
1931 |
// </editor-fold> |
|
1932 |
||
1933 |
// <editor-fold defaultstate="collapsed" desc="getBounds"> |
|
1934 |
/** |
|
1935 |
* Return list of bounds of the given type variable. |
|
1936 |
*/ |
|
1937 |
public List<Type> getBounds(TypeVar t) { |
|
1938 |
if (t.bound.isErroneous() || !t.bound.isCompound()) |
|
1939 |
return List.of(t.bound); |
|
1940 |
else if ((erasure(t).tsym.flags() & INTERFACE) == 0) |
|
1941 |
return interfaces(t).prepend(supertype(t)); |
|
1942 |
else |
|
1943 |
// No superclass was given in bounds. |
|
1944 |
// In this case, supertype is Object, erasure is first interface. |
|
1945 |
return interfaces(t); |
|
1946 |
} |
|
1947 |
// </editor-fold> |
|
1948 |
||
1949 |
// <editor-fold defaultstate="collapsed" desc="classBound"> |
|
1950 |
/** |
|
1951 |
* If the given type is a (possibly selected) type variable, |
|
1952 |
* return the bounding class of this type, otherwise return the |
|
1953 |
* type itself. |
|
1954 |
*/ |
|
1955 |
public Type classBound(Type t) { |
|
1956 |
return classBound.visit(t); |
|
1957 |
} |
|
1958 |
// where |
|
1959 |
private UnaryVisitor<Type> classBound = new UnaryVisitor<Type>() { |
|
1960 |
||
1961 |
public Type visitType(Type t, Void ignored) { |
|
1962 |
return t; |
|
1963 |
} |
|
1964 |
||
1965 |
@Override |
|
1966 |
public Type visitClassType(ClassType t, Void ignored) { |
|
1967 |
Type outer1 = classBound(t.getEnclosingType()); |
|
1968 |
if (outer1 != t.getEnclosingType()) |
|
1969 |
return new ClassType(outer1, t.getTypeArguments(), t.tsym); |
|
1970 |
else |
|
1971 |
return t; |
|
1972 |
} |
|
1973 |
||
1974 |
@Override |
|
1975 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
1976 |
return classBound(supertype(t)); |
|
1977 |
} |
|
1978 |
||
1979 |
@Override |
|
1980 |
public Type visitErrorType(ErrorType t, Void ignored) { |
|
1981 |
return t; |
|
1982 |
} |
|
1983 |
}; |
|
1984 |
// </editor-fold> |
|
1985 |
||
1986 |
// <editor-fold defaultstate="collapsed" desc="sub signature / override equivalence"> |
|
1987 |
/** |
|
1988 |
* Returns true iff the first signature is a <em>sub |
|
1989 |
* signature</em> of the other. This is <b>not</b> an equivalence |
|
1990 |
* relation. |
|
1991 |
* |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
1992 |
* @jls section 8.4.2. |
10 | 1993 |
* @see #overrideEquivalent(Type t, Type s) |
1994 |
* @param t first signature (possibly raw). |
|
1995 |
* @param s second signature (could be subjected to erasure). |
|
1996 |
* @return true if t is a sub signature of s. |
|
1997 |
*/ |
|
1998 |
public boolean isSubSignature(Type t, Type s) { |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
1999 |
return isSubSignature(t, s, true); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2000 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2001 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2002 |
public boolean isSubSignature(Type t, Type s, boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2003 |
return hasSameArgs(t, s, strict) || hasSameArgs(t, erasure(s), strict); |
10 | 2004 |
} |
2005 |
||
2006 |
/** |
|
2007 |
* Returns true iff these signatures are related by <em>override |
|
2008 |
* equivalence</em>. This is the natural extension of |
|
2009 |
* isSubSignature to an equivalence relation. |
|
2010 |
* |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
2011 |
* @jls section 8.4.2. |
10 | 2012 |
* @see #isSubSignature(Type t, Type s) |
2013 |
* @param t a signature (possible raw, could be subjected to |
|
2014 |
* erasure). |
|
2015 |
* @param s a signature (possible raw, could be subjected to |
|
2016 |
* erasure). |
|
2017 |
* @return true if either argument is a sub signature of the other. |
|
2018 |
*/ |
|
2019 |
public boolean overrideEquivalent(Type t, Type s) { |
|
2020 |
return hasSameArgs(t, s) || |
|
2021 |
hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s); |
|
2022 |
} |
|
2023 |
||
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2024 |
// <editor-fold defaultstate="collapsed" desc="Determining method implementation in given site"> |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2025 |
class ImplementationCache { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2026 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2027 |
private WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>> _map = |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2028 |
new WeakHashMap<MethodSymbol, SoftReference<Map<TypeSymbol, Entry>>>(); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2029 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2030 |
class Entry { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2031 |
final MethodSymbol cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2032 |
final Filter<Symbol> implFilter; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2033 |
final boolean checkResult; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2034 |
final int prevMark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2035 |
|
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2036 |
public Entry(MethodSymbol cachedImpl, |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2037 |
Filter<Symbol> scopeFilter, |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2038 |
boolean checkResult, |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2039 |
int prevMark) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2040 |
this.cachedImpl = cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2041 |
this.implFilter = scopeFilter; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2042 |
this.checkResult = checkResult; |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2043 |
this.prevMark = prevMark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2044 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2045 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2046 |
boolean matches(Filter<Symbol> scopeFilter, boolean checkResult, int mark) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2047 |
return this.implFilter == scopeFilter && |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2048 |
this.checkResult == checkResult && |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2049 |
this.prevMark == mark; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2050 |
} |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2051 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2052 |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2053 |
MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2054 |
SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2055 |
Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2056 |
if (cache == null) { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2057 |
cache = new HashMap<TypeSymbol, Entry>(); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2058 |
_map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache)); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2059 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2060 |
Entry e = cache.get(origin); |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2061 |
CompoundScope members = membersClosure(origin.type); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2062 |
if (e == null || |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2063 |
!e.matches(implFilter, checkResult, members.getMark())) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2064 |
MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2065 |
cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark())); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2066 |
return impl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2067 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2068 |
else { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2069 |
return e.cachedImpl; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2070 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2071 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2072 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2073 |
private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2074 |
for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = supertype(t)) { |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2075 |
while (t.tag == TYPEVAR) |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2076 |
t = t.getUpperBound(); |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2077 |
TypeSymbol c = t.tsym; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2078 |
for (Scope.Entry e = c.members().lookup(ms.name, implFilter); |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2079 |
e.scope != null; |
7628
e7baeb97d164
6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents:
7627
diff
changeset
|
2080 |
e = e.next(implFilter)) { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2081 |
if (e.sym != null && |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2082 |
e.sym.overrides(ms, origin, Types.this, checkResult)) |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2083 |
return (MethodSymbol)e.sym; |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2084 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2085 |
} |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2086 |
return null; |
3539
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2087 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2088 |
} |
3c265cb6f4e0
6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents:
3140
diff
changeset
|
2089 |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2090 |
private ImplementationCache implCache = new ImplementationCache(); |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2091 |
|
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2092 |
public MethodSymbol implementation(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2093 |
return implCache.get(ms, origin, checkResult, implFilter); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2094 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2095 |
// </editor-fold> |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2096 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2097 |
// <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2098 |
public CompoundScope membersClosure(Type site) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2099 |
return membersClosure.visit(site); |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2100 |
} |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2101 |
|
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2102 |
UnaryVisitor<CompoundScope> membersClosure = new UnaryVisitor<CompoundScope>() { |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2103 |
|
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2104 |
public CompoundScope visitType(Type t, Void s) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2105 |
return null; |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2106 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2107 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2108 |
@Override |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2109 |
public CompoundScope visitClassType(ClassType t, Void s) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2110 |
ClassSymbol csym = (ClassSymbol)t.tsym; |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2111 |
if (csym.membersClosure == null) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2112 |
CompoundScope membersClosure = new CompoundScope(csym); |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2113 |
for (Type i : interfaces(t)) { |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2114 |
membersClosure.addSubScope(visit(i)); |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2115 |
} |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2116 |
membersClosure.addSubScope(visit(supertype(t))); |
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2117 |
membersClosure.addSubScope(csym.members()); |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2118 |
csym.membersClosure = membersClosure; |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2119 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2120 |
return csym.membersClosure; |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2121 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2122 |
|
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2123 |
@Override |
8427
703181b01773
7017664: Add listeners infrastracture to javac scopes
mcimadamore
parents:
8242
diff
changeset
|
2124 |
public CompoundScope visitTypeVar(TypeVar t, Void s) { |
8242
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2125 |
return visit(t.getUpperBound()); |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2126 |
} |
3873b4aaf4a8
7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents:
8230
diff
changeset
|
2127 |
}; |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2128 |
// </editor-fold> |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6583
diff
changeset
|
2129 |
|
10 | 2130 |
/** |
2131 |
* Does t have the same arguments as s? It is assumed that both |
|
2132 |
* types are (possibly polymorphic) method types. Monomorphic |
|
2133 |
* method types "have the same arguments", if their argument lists |
|
2134 |
* are equal. Polymorphic method types "have the same arguments", |
|
2135 |
* if they have the same arguments after renaming all type |
|
2136 |
* variables of one to corresponding type variables in the other, |
|
2137 |
* where correspondence is by position in the type parameter list. |
|
2138 |
*/ |
|
2139 |
public boolean hasSameArgs(Type t, Type s) { |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2140 |
return hasSameArgs(t, s, true); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2141 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2142 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2143 |
public boolean hasSameArgs(Type t, Type s, boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2144 |
return hasSameArgs(t, s, strict ? hasSameArgs_strict : hasSameArgs_nonstrict); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2145 |
} |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2146 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2147 |
private boolean hasSameArgs(Type t, Type s, TypeRelation hasSameArgs) { |
10 | 2148 |
return hasSameArgs.visit(t, s); |
2149 |
} |
|
2150 |
// where |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2151 |
private class HasSameArgs extends TypeRelation { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2152 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2153 |
boolean strict; |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2154 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2155 |
public HasSameArgs(boolean strict) { |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2156 |
this.strict = strict; |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2157 |
} |
10 | 2158 |
|
2159 |
public Boolean visitType(Type t, Type s) { |
|
2160 |
throw new AssertionError(); |
|
2161 |
} |
|
2162 |
||
2163 |
@Override |
|
2164 |
public Boolean visitMethodType(MethodType t, Type s) { |
|
2165 |
return s.tag == METHOD |
|
2166 |
&& containsTypeEquivalent(t.argtypes, s.getParameterTypes()); |
|
2167 |
} |
|
2168 |
||
2169 |
@Override |
|
2170 |
public Boolean visitForAll(ForAll t, Type s) { |
|
2171 |
if (s.tag != FORALL) |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2172 |
return strict ? false : visitMethodType(t.asMethodType(), s); |
10 | 2173 |
|
2174 |
ForAll forAll = (ForAll)s; |
|
2175 |
return hasSameBounds(t, forAll) |
|
2176 |
&& visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars)); |
|
2177 |
} |
|
2178 |
||
2179 |
@Override |
|
2180 |
public Boolean visitErrorType(ErrorType t, Type s) { |
|
2181 |
return false; |
|
2182 |
} |
|
2183 |
}; |
|
8628
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2184 |
|
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2185 |
TypeRelation hasSameArgs_strict = new HasSameArgs(true); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2186 |
TypeRelation hasSameArgs_nonstrict = new HasSameArgs(false); |
9e31f1c01bd4
7022054: Invalid compiler error on covariant overriding methods with the same erasure
mcimadamore
parents:
8625
diff
changeset
|
2187 |
|
10 | 2188 |
// </editor-fold> |
2189 |
||
2190 |
// <editor-fold defaultstate="collapsed" desc="subst"> |
|
2191 |
public List<Type> subst(List<Type> ts, |
|
2192 |
List<Type> from, |
|
2193 |
List<Type> to) { |
|
2194 |
return new Subst(from, to).subst(ts); |
|
2195 |
} |
|
2196 |
||
2197 |
/** |
|
2198 |
* Substitute all occurrences of a type in `from' with the |
|
2199 |
* corresponding type in `to' in 't'. Match lists `from' and `to' |
|
2200 |
* from the right: If lists have different length, discard leading |
|
2201 |
* elements of the longer list. |
|
2202 |
*/ |
|
2203 |
public Type subst(Type t, List<Type> from, List<Type> to) { |
|
2204 |
return new Subst(from, to).subst(t); |
|
2205 |
} |
|
2206 |
||
2207 |
private class Subst extends UnaryVisitor<Type> { |
|
2208 |
List<Type> from; |
|
2209 |
List<Type> to; |
|
2210 |
||
2211 |
public Subst(List<Type> from, List<Type> to) { |
|
2212 |
int fromLength = from.length(); |
|
2213 |
int toLength = to.length(); |
|
2214 |
while (fromLength > toLength) { |
|
2215 |
fromLength--; |
|
2216 |
from = from.tail; |
|
2217 |
} |
|
2218 |
while (fromLength < toLength) { |
|
2219 |
toLength--; |
|
2220 |
to = to.tail; |
|
2221 |
} |
|
2222 |
this.from = from; |
|
2223 |
this.to = to; |
|
2224 |
} |
|
2225 |
||
2226 |
Type subst(Type t) { |
|
2227 |
if (from.tail == null) |
|
2228 |
return t; |
|
2229 |
else |
|
2230 |
return visit(t); |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
2231 |
} |
10 | 2232 |
|
2233 |
List<Type> subst(List<Type> ts) { |
|
2234 |
if (from.tail == null) |
|
2235 |
return ts; |
|
2236 |
boolean wild = false; |
|
2237 |
if (ts.nonEmpty() && from.nonEmpty()) { |
|
2238 |
Type head1 = subst(ts.head); |
|
2239 |
List<Type> tail1 = subst(ts.tail); |
|
2240 |
if (head1 != ts.head || tail1 != ts.tail) |
|
2241 |
return tail1.prepend(head1); |
|
2242 |
} |
|
2243 |
return ts; |
|
2244 |
} |
|
2245 |
||
2246 |
public Type visitType(Type t, Void ignored) { |
|
2247 |
return t; |
|
2248 |
} |
|
2249 |
||
2250 |
@Override |
|
2251 |
public Type visitMethodType(MethodType t, Void ignored) { |
|
2252 |
List<Type> argtypes = subst(t.argtypes); |
|
2253 |
Type restype = subst(t.restype); |
|
2254 |
List<Type> thrown = subst(t.thrown); |
|
2255 |
if (argtypes == t.argtypes && |
|
2256 |
restype == t.restype && |
|
2257 |
thrown == t.thrown) |
|
2258 |
return t; |
|
2259 |
else |
|
2260 |
return new MethodType(argtypes, restype, thrown, t.tsym); |
|
2261 |
} |
|
2262 |
||
2263 |
@Override |
|
2264 |
public Type visitTypeVar(TypeVar t, Void ignored) { |
|
2265 |
for (List<Type> from = this.from, to = this.to; |
|
2266 |
from.nonEmpty(); |
|
2267 |
from = from.tail, to = to.tail) { |
|
2268 |
if (t == from.head) { |
|
2269 |
return to.head.withTypeVar(t); |
|
2270 |
} |
|
2271 |
} |
|
2272 |
return t; |
|
2273 |
} |
|
2274 |
||
2275 |
@Override |
|
2276 |
public Type visitClassType(ClassType t, Void ignored) { |
|
2277 |
if (!t.isCompound()) { |
|
2278 |
List<Type> typarams = t.getTypeArguments(); |
|
2279 |
List<Type> typarams1 = subst(typarams); |
|
2280 |
Type outer = t.getEnclosingType(); |
|
2281 |
Type outer1 = subst(outer); |
|
2282 |
if (typarams1 == typarams && outer1 == outer) |
|
2283 |
return t; |
|
2284 |
else |
|
2285 |
return new ClassType(outer1, typarams1, t.tsym); |
|
2286 |
} else { |
|
2287 |
Type st = subst(supertype(t)); |
|
2288 |
List<Type> is = upperBounds(subst(interfaces(t))); |
|
2289 |
if (st == supertype(t) && is == interfaces(t)) |
|
2290 |
return t; |
|
2291 |
else |
|
2292 |
return makeCompoundType(is.prepend(st)); |
|
2293 |
} |
|
2294 |
} |
|
2295 |
||
2296 |
@Override |
|
2297 |
public Type visitWildcardType(WildcardType t, Void ignored) { |
|
2298 |
Type bound = t.type; |
|
2299 |
if (t.kind != BoundKind.UNBOUND) |
|
2300 |
bound = subst(bound); |
|
2301 |
if (bound == t.type) { |
|
2302 |
return t; |
|
2303 |
} else { |
|
2304 |
if (t.isExtendsBound() && bound.isExtendsBound()) |
|
2305 |
bound = upperBound(bound); |
|
2306 |
return new WildcardType(bound, t.kind, syms.boundClass, t.bound); |
|
2307 |
} |
|
2308 |
} |
|
2309 |
||
2310 |
@Override |
|
2311 |
public Type visitArrayType(ArrayType t, Void ignored) { |
|
2312 |
Type elemtype = subst(t.elemtype); |
|
2313 |
if (elemtype == t.elemtype) |
|
2314 |
return t; |
|
2315 |
else |
|
9301 | 2316 |
return new ArrayType(elemtype, t.tsym); |
10 | 2317 |
} |
2318 |
||
2319 |
@Override |
|
2320 |
public Type visitForAll(ForAll t, Void ignored) { |
|
8230
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2321 |
if (Type.containsAny(to, t.tvars)) { |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2322 |
//perform alpha-renaming of free-variables in 't' |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2323 |
//if 'to' types contain variables that are free in 't' |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2324 |
List<Type> freevars = newInstances(t.tvars); |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2325 |
t = new ForAll(freevars, |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2326 |
Types.this.subst(t.qtype, t.tvars, freevars)); |
b761a23e78d8
6838943: inference: javac is not handling type-variable substitution properly
mcimadamore
parents:
8032
diff
changeset
|
2327 |
} |
10 | 2328 |
List<Type> tvars1 = substBounds(t.tvars, from, to); |
2329 |
Type qtype1 = subst(t.qtype); |
|
2330 |
if (tvars1 == t.tvars && qtype1 == t.qtype) { |
|
2331 |
return t; |
|
2332 |
} else if (tvars1 == t.tvars) { |
|
2333 |
return new ForAll(tvars1, qtype1); |
|
2334 |
} else { |
|
2335 |
return new ForAll(tvars1, Types.this.subst(qtype1, t.tvars, tvars1)); |
|
2336 |
} |
|
2337 |
} |
|
2338 |
||
2339 |
@Override |
|
2340 |
public Type visitErrorType(ErrorType t, Void ignored) { |
|
2341 |
return t; |
|
2342 |
} |
|
2343 |
} |
|
2344 |
||
2345 |
public List<Type> substBounds(List<Type> tvars, |
|
2346 |
List<Type> from, |
|
2347 |
List<Type> to) { |
|
2348 |
if (tvars.isEmpty()) |
|
2349 |
return tvars; |
|
2350 |
ListBuffer<Type> newBoundsBuf = lb(); |
|
2351 |
boolean changed = false; |
|
2352 |
// calculate new bounds |
|
2353 |
for (Type t : tvars) { |
|
2354 |
TypeVar tv = (TypeVar) t; |
|
2355 |
Type bound = subst(tv.bound, from, to); |
|
2356 |
if (bound != tv.bound) |
|
2357 |
changed = true; |
|
2358 |
newBoundsBuf.append(bound); |
|
2359 |
} |
|
2360 |
if (!changed) |
|
2361 |
return tvars; |
|
2362 |
ListBuffer<Type> newTvars = lb(); |
|
2363 |
// create new type variables without bounds |
|
2364 |
for (Type t : tvars) { |
|
2365 |
newTvars.append(new TypeVar(t.tsym, null, syms.botType)); |
|
2366 |
} |
|
2367 |
// the new bounds should use the new type variables in place |
|
2368 |
// of the old |
|
2369 |
List<Type> newBounds = newBoundsBuf.toList(); |
|
2370 |
from = tvars; |
|
2371 |
to = newTvars.toList(); |
|
2372 |
for (; !newBounds.isEmpty(); newBounds = newBounds.tail) { |
|
2373 |
newBounds.head = subst(newBounds.head, from, to); |
|
2374 |
} |
|
2375 |
newBounds = newBoundsBuf.toList(); |
|
2376 |
// set the bounds of new type variables to the new bounds |
|
2377 |
for (Type t : newTvars.toList()) { |
|
2378 |
TypeVar tv = (TypeVar) t; |
|
2379 |
tv.bound = newBounds.head; |
|
2380 |
newBounds = newBounds.tail; |
|
2381 |
} |
|
2382 |
return newTvars.toList(); |
|
2383 |
} |
|
2384 |
||
2385 |
public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) { |
|
2386 |
Type bound1 = subst(t.bound, from, to); |
|
2387 |
if (bound1 == t.bound) |
|
2388 |
return t; |
|
1993
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2389 |
else { |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2390 |
// create new type variable without bounds |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2391 |
TypeVar tv = new TypeVar(t.tsym, null, syms.botType); |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2392 |
// the new bound should use the new type variable in place |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2393 |
// of the old |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2394 |
tv.bound = subst(bound1, List.<Type>of(t), List.<Type>of(tv)); |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2395 |
return tv; |
9b37ef07ba64
6729401: Compiler error when using F-bounded generics with free type variables
mcimadamore
parents:
1992
diff
changeset
|
2396 |
} |
10 | 2397 |
} |
2398 |
// </editor-fold> |
|
2399 |
||
2400 |
// <editor-fold defaultstate="collapsed" desc="hasSameBounds"> |
|
2401 |
/** |
|
2402 |
* Does t have the same bounds for quantified variables as s? |
|
2403 |
*/ |
|
2404 |
boolean hasSameBounds(ForAll t, ForAll s) { |
|
2405 |
List<Type> l1 = t.tvars; |
|
2406 |
List<Type> l2 = s.tvars; |
|
2407 |
while (l1.nonEmpty() && l2.nonEmpty() && |
|
2408 |
isSameType(l1.head.getUpperBound(), |
|
2409 |
subst(l2.head.getUpperBound(), |
|
2410 |
s.tvars, |
|
2411 |
t.tvars))) { |
|
2412 |
l1 = l1.tail; |
|
2413 |
l2 = l2.tail; |
|
2414 |
} |
|
2415 |
return l1.isEmpty() && l2.isEmpty(); |
|
2416 |
} |
|
2417 |
// </editor-fold> |
|
2418 |
||
2419 |
// <editor-fold defaultstate="collapsed" desc="newInstances"> |
|
2420 |
/** Create new vector of type variables from list of variables |
|
2421 |
* changing all recursive bounds from old to new list. |
|
2422 |
*/ |
|
2423 |
public List<Type> newInstances(List<Type> tvars) { |
|
2424 |
List<Type> tvars1 = Type.map(tvars, newInstanceFun); |
|
2425 |
for (List<Type> l = tvars1; l.nonEmpty(); l = l.tail) { |
|
2426 |
TypeVar tv = (TypeVar) l.head; |
|
2427 |
tv.bound = subst(tv.bound, tvars, tvars1); |
|
2428 |
} |
|
2429 |
return tvars1; |
|
2430 |
} |
|
2431 |
static private Mapping newInstanceFun = new Mapping("newInstanceFun") { |
|
2432 |
public Type apply(Type t) { return new TypeVar(t.tsym, t.getUpperBound(), t.getLowerBound()); } |
|
2433 |
}; |
|
2434 |
// </editor-fold> |
|
2435 |
||
8430 | 2436 |
public Type createMethodTypeWithParameters(Type original, List<Type> newParams) { |
2437 |
return original.accept(methodWithParameters, newParams); |
|
2438 |
} |
|
2439 |
// where |
|
2440 |
private final MapVisitor<List<Type>> methodWithParameters = new MapVisitor<List<Type>>() { |
|
2441 |
public Type visitType(Type t, List<Type> newParams) { |
|
2442 |
throw new IllegalArgumentException("Not a method type: " + t); |
|
2443 |
} |
|
2444 |
public Type visitMethodType(MethodType t, List<Type> newParams) { |
|
2445 |
return new MethodType(newParams, t.restype, t.thrown, t.tsym); |
|
2446 |
} |
|
2447 |
public Type visitForAll(ForAll t, List<Type> newParams) { |
|
2448 |
return new ForAll(t.tvars, t.qtype.accept(this, newParams)); |
|
2449 |
} |
|
2450 |
}; |
|
2451 |
||
2452 |
public Type createMethodTypeWithThrown(Type original, List<Type> newThrown) { |
|
2453 |
return original.accept(methodWithThrown, newThrown); |
|
2454 |
} |
|
2455 |
// where |
|
2456 |
private final MapVisitor<List<Type>> methodWithThrown = new MapVisitor<List<Type>>() { |
|
2457 |
public Type visitType(Type t, List<Type> newThrown) { |
|
2458 |
throw new IllegalArgumentException("Not a method type: " + t); |
|
2459 |
} |
|
2460 |
public Type visitMethodType(MethodType t, List<Type> newThrown) { |
|
2461 |
return new MethodType(t.argtypes, t.restype, newThrown, t.tsym); |
|
2462 |
} |
|
2463 |
public Type visitForAll(ForAll t, List<Type> newThrown) { |
|
2464 |
return new ForAll(t.tvars, t.qtype.accept(this, newThrown)); |
|
2465 |
} |
|
2466 |
}; |
|
2467 |
||
9075
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2468 |
public Type createMethodTypeWithReturn(Type original, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2469 |
return original.accept(methodWithReturn, newReturn); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2470 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2471 |
// where |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2472 |
private final MapVisitor<Type> methodWithReturn = new MapVisitor<Type>() { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2473 |
public Type visitType(Type t, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2474 |
throw new IllegalArgumentException("Not a method type: " + t); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2475 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2476 |
public Type visitMethodType(MethodType t, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2477 |
return new MethodType(t.argtypes, newReturn, t.thrown, t.tsym); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2478 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2479 |
public Type visitForAll(ForAll t, Type newReturn) { |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2480 |
return new ForAll(t.tvars, t.qtype.accept(this, newReturn)); |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2481 |
} |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2482 |
}; |
cba34854a40e
7030150: Type inference for generic instance creation failed for formal type parameter
mcimadamore
parents:
8628
diff
changeset
|
2483 |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2484 |
// <editor-fold defaultstate="collapsed" desc="createErrorType"> |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2485 |
public Type createErrorType(Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2486 |
return new ErrorType(originalType, syms.errSymbol); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2487 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2488 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2489 |
public Type createErrorType(ClassSymbol c, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2490 |
return new ErrorType(c, originalType); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2491 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2492 |
|
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2493 |
public Type createErrorType(Name name, TypeSymbol container, Type originalType) { |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2494 |
return new ErrorType(name, container, originalType); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2495 |
} |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2496 |
// </editor-fold> |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2497 |
|
10 | 2498 |
// <editor-fold defaultstate="collapsed" desc="rank"> |
2499 |
/** |
|
2500 |
* The rank of a class is the length of the longest path between |
|
2501 |
* the class and java.lang.Object in the class inheritance |
|
2502 |
* graph. Undefined for all but reference types. |
|
2503 |
*/ |
|
2504 |
public int rank(Type t) { |
|
2505 |
switch(t.tag) { |
|
2506 |
case CLASS: { |
|
2507 |
ClassType cls = (ClassType)t; |
|
2508 |
if (cls.rank_field < 0) { |
|
2509 |
Name fullname = cls.tsym.getQualifiedName(); |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
2510 |
if (fullname == names.java_lang_Object) |
10 | 2511 |
cls.rank_field = 0; |
2512 |
else { |
|
2513 |
int r = rank(supertype(cls)); |
|
2514 |
for (List<Type> l = interfaces(cls); |
|
2515 |
l.nonEmpty(); |
|
2516 |
l = l.tail) { |
|
2517 |
if (rank(l.head) > r) |
|
2518 |
r = rank(l.head); |
|
2519 |
} |
|
2520 |
cls.rank_field = r + 1; |
|
2521 |
} |
|
2522 |
} |
|
2523 |
return cls.rank_field; |
|
2524 |
} |
|
2525 |
case TYPEVAR: { |
|
2526 |
TypeVar tvar = (TypeVar)t; |
|
2527 |
if (tvar.rank_field < 0) { |
|
2528 |
int r = rank(supertype(tvar)); |
|
2529 |
for (List<Type> l = interfaces(tvar); |
|
2530 |
l.nonEmpty(); |
|
2531 |
l = l.tail) { |
|
2532 |
if (rank(l.head) > r) r = rank(l.head); |
|
2533 |
} |
|
2534 |
tvar.rank_field = r + 1; |
|
2535 |
} |
|
2536 |
return tvar.rank_field; |
|
2537 |
} |
|
2538 |
case ERROR: |
|
2539 |
return 0; |
|
2540 |
default: |
|
2541 |
throw new AssertionError(); |
|
2542 |
} |
|
2543 |
} |
|
2544 |
// </editor-fold> |
|
2545 |
||
1357 | 2546 |
/** |
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
2547 |
* Helper method for generating a string representation of a given type |
1357 | 2548 |
* accordingly to a given locale |
2549 |
*/ |
|
2550 |
public String toString(Type t, Locale locale) { |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
2551 |
return Printer.createStandardPrinter(messages).visit(t, locale); |
1357 | 2552 |
} |
2553 |
||
2554 |
/** |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
2555 |
* Helper method for generating a string representation of a given type |
1357 | 2556 |
* accordingly to a given locale |
2557 |
*/ |
|
2558 |
public String toString(Symbol t, Locale locale) { |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
2559 |
return Printer.createStandardPrinter(messages).visit(t, locale); |
1357 | 2560 |
} |
2561 |
||
10 | 2562 |
// <editor-fold defaultstate="collapsed" desc="toString"> |
2563 |
/** |
|
2564 |
* This toString is slightly more descriptive than the one on Type. |
|
1357 | 2565 |
* |
2566 |
* @deprecated Types.toString(Type t, Locale l) provides better support |
|
2567 |
* for localization |
|
10 | 2568 |
*/ |
1357 | 2569 |
@Deprecated |
10 | 2570 |
public String toString(Type t) { |
2571 |
if (t.tag == FORALL) { |
|
2572 |
ForAll forAll = (ForAll)t; |
|
2573 |
return typaramsString(forAll.tvars) + forAll.qtype; |
|
2574 |
} |
|
2575 |
return "" + t; |
|
2576 |
} |
|
2577 |
// where |
|
2578 |
private String typaramsString(List<Type> tvars) { |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8617
diff
changeset
|
2579 |
StringBuilder s = new StringBuilder(); |
10 | 2580 |
s.append('<'); |
2581 |
boolean first = true; |
|
2582 |
for (Type t : tvars) { |
|
2583 |
if (!first) s.append(", "); |
|
2584 |
first = false; |
|
2585 |
appendTyparamString(((TypeVar)t), s); |
|
2586 |
} |
|
2587 |
s.append('>'); |
|
2588 |
return s.toString(); |
|
2589 |
} |
|
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8617
diff
changeset
|
2590 |
private void appendTyparamString(TypeVar t, StringBuilder buf) { |
10 | 2591 |
buf.append(t); |
2592 |
if (t.bound == null || |
|
2593 |
t.bound.tsym.getQualifiedName() == names.java_lang_Object) |
|
2594 |
return; |
|
2595 |
buf.append(" extends "); // Java syntax; no need for i18n |
|
2596 |
Type bound = t.bound; |
|
2597 |
if (!bound.isCompound()) { |
|
2598 |
buf.append(bound); |
|
2599 |
} else if ((erasure(t).tsym.flags() & INTERFACE) == 0) { |
|
2600 |
buf.append(supertype(t)); |
|
2601 |
for (Type intf : interfaces(t)) { |
|
2602 |
buf.append('&'); |
|
2603 |
buf.append(intf); |
|
2604 |
} |
|
2605 |
} else { |
|
2606 |
// No superclass was given in bounds. |
|
2607 |
// In this case, supertype is Object, erasure is first interface. |
|
2608 |
boolean first = true; |
|
2609 |
for (Type intf : interfaces(t)) { |
|
2610 |
if (!first) buf.append('&'); |
|
2611 |
first = false; |
|
2612 |
buf.append(intf); |
|
2613 |
} |
|
2614 |
} |
|
2615 |
} |
|
2616 |
// </editor-fold> |
|
2617 |
||
2618 |
// <editor-fold defaultstate="collapsed" desc="Determining least upper bounds of types"> |
|
2619 |
/** |
|
2620 |
* A cache for closures. |
|
2621 |
* |
|
2622 |
* <p>A closure is a list of all the supertypes and interfaces of |
|
2623 |
* a class or interface type, ordered by ClassSymbol.precedes |
|
2624 |
* (that is, subclasses come first, arbitrary but fixed |
|
2625 |
* otherwise). |
|
2626 |
*/ |
|
2627 |
private Map<Type,List<Type>> closureCache = new HashMap<Type,List<Type>>(); |
|
2628 |
||
2629 |
/** |
|
2630 |
* Returns the closure of a class or interface type. |
|
2631 |
*/ |
|
2632 |
public List<Type> closure(Type t) { |
|
2633 |
List<Type> cl = closureCache.get(t); |
|
2634 |
if (cl == null) { |
|
2635 |
Type st = supertype(t); |
|
2636 |
if (!t.isCompound()) { |
|
2637 |
if (st.tag == CLASS) { |
|
2638 |
cl = insert(closure(st), t); |
|
2639 |
} else if (st.tag == TYPEVAR) { |
|
2640 |
cl = closure(st).prepend(t); |
|
2641 |
} else { |
|
2642 |
cl = List.of(t); |
|
2643 |
} |
|
2644 |
} else { |
|
2645 |
cl = closure(supertype(t)); |
|
2646 |
} |
|
2647 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) |
|
2648 |
cl = union(cl, closure(l.head)); |
|
2649 |
closureCache.put(t, cl); |
|
2650 |
} |
|
2651 |
return cl; |
|
2652 |
} |
|
2653 |
||
2654 |
/** |
|
2655 |
* Insert a type in a closure |
|
2656 |
*/ |
|
2657 |
public List<Type> insert(List<Type> cl, Type t) { |
|
2658 |
if (cl.isEmpty() || t.tsym.precedes(cl.head.tsym, this)) { |
|
2659 |
return cl.prepend(t); |
|
2660 |
} else if (cl.head.tsym.precedes(t.tsym, this)) { |
|
2661 |
return insert(cl.tail, t).prepend(cl.head); |
|
2662 |
} else { |
|
2663 |
return cl; |
|
2664 |
} |
|
2665 |
} |
|
2666 |
||
2667 |
/** |
|
2668 |
* Form the union of two closures |
|
2669 |
*/ |
|
2670 |
public List<Type> union(List<Type> cl1, List<Type> cl2) { |
|
2671 |
if (cl1.isEmpty()) { |
|
2672 |
return cl2; |
|
2673 |
} else if (cl2.isEmpty()) { |
|
2674 |
return cl1; |
|
2675 |
} else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) { |
|
2676 |
return union(cl1.tail, cl2).prepend(cl1.head); |
|
2677 |
} else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) { |
|
2678 |
return union(cl1, cl2.tail).prepend(cl2.head); |
|
2679 |
} else { |
|
2680 |
return union(cl1.tail, cl2.tail).prepend(cl1.head); |
|
2681 |
} |
|
2682 |
} |
|
2683 |
||
2684 |
/** |
|
2685 |
* Intersect two closures |
|
2686 |
*/ |
|
2687 |
public List<Type> intersect(List<Type> cl1, List<Type> cl2) { |
|
2688 |
if (cl1 == cl2) |
|
2689 |
return cl1; |
|
2690 |
if (cl1.isEmpty() || cl2.isEmpty()) |
|
2691 |
return List.nil(); |
|
2692 |
if (cl1.head.tsym.precedes(cl2.head.tsym, this)) |
|
2693 |
return intersect(cl1.tail, cl2); |
|
2694 |
if (cl2.head.tsym.precedes(cl1.head.tsym, this)) |
|
2695 |
return intersect(cl1, cl2.tail); |
|
2696 |
if (isSameType(cl1.head, cl2.head)) |
|
2697 |
return intersect(cl1.tail, cl2.tail).prepend(cl1.head); |
|
2698 |
if (cl1.head.tsym == cl2.head.tsym && |
|
2699 |
cl1.head.tag == CLASS && cl2.head.tag == CLASS) { |
|
2700 |
if (cl1.head.isParameterized() && cl2.head.isParameterized()) { |
|
2701 |
Type merge = merge(cl1.head,cl2.head); |
|
2702 |
return intersect(cl1.tail, cl2.tail).prepend(merge); |
|
2703 |
} |
|
2704 |
if (cl1.head.isRaw() || cl2.head.isRaw()) |
|
2705 |
return intersect(cl1.tail, cl2.tail).prepend(erasure(cl1.head)); |
|
2706 |
} |
|
2707 |
return intersect(cl1.tail, cl2.tail); |
|
2708 |
} |
|
2709 |
// where |
|
2710 |
class TypePair { |
|
2711 |
final Type t1; |
|
2712 |
final Type t2; |
|
2713 |
TypePair(Type t1, Type t2) { |
|
2714 |
this.t1 = t1; |
|
2715 |
this.t2 = t2; |
|
2716 |
} |
|
2717 |
@Override |
|
2718 |
public int hashCode() { |
|
5004
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
3554
diff
changeset
|
2719 |
return 127 * Types.hashCode(t1) + Types.hashCode(t2); |
10 | 2720 |
} |
2721 |
@Override |
|
2722 |
public boolean equals(Object obj) { |
|
2723 |
if (!(obj instanceof TypePair)) |
|
2724 |
return false; |
|
2725 |
TypePair typePair = (TypePair)obj; |
|
2726 |
return isSameType(t1, typePair.t1) |
|
2727 |
&& isSameType(t2, typePair.t2); |
|
2728 |
} |
|
2729 |
} |
|
2730 |
Set<TypePair> mergeCache = new HashSet<TypePair>(); |
|
2731 |
private Type merge(Type c1, Type c2) { |
|
2732 |
ClassType class1 = (ClassType) c1; |
|
2733 |
List<Type> act1 = class1.getTypeArguments(); |
|
2734 |
ClassType class2 = (ClassType) c2; |
|
2735 |
List<Type> act2 = class2.getTypeArguments(); |
|
2736 |
ListBuffer<Type> merged = new ListBuffer<Type>(); |
|
2737 |
List<Type> typarams = class1.tsym.type.getTypeArguments(); |
|
2738 |
||
2739 |
while (act1.nonEmpty() && act2.nonEmpty() && typarams.nonEmpty()) { |
|
2740 |
if (containsType(act1.head, act2.head)) { |
|
2741 |
merged.append(act1.head); |
|
2742 |
} else if (containsType(act2.head, act1.head)) { |
|
2743 |
merged.append(act2.head); |
|
2744 |
} else { |
|
2745 |
TypePair pair = new TypePair(c1, c2); |
|
2746 |
Type m; |
|
2747 |
if (mergeCache.add(pair)) { |
|
2748 |
m = new WildcardType(lub(upperBound(act1.head), |
|
2749 |
upperBound(act2.head)), |
|
2750 |
BoundKind.EXTENDS, |
|
2751 |
syms.boundClass); |
|
2752 |
mergeCache.remove(pair); |
|
2753 |
} else { |
|
2754 |
m = new WildcardType(syms.objectType, |
|
2755 |
BoundKind.UNBOUND, |
|
2756 |
syms.boundClass); |
|
2757 |
} |
|
2758 |
merged.append(m.withTypeVar(typarams.head)); |
|
2759 |
} |
|
2760 |
act1 = act1.tail; |
|
2761 |
act2 = act2.tail; |
|
2762 |
typarams = typarams.tail; |
|
2763 |
} |
|
8032 | 2764 |
Assert.check(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty()); |
10 | 2765 |
return new ClassType(class1.getEnclosingType(), merged.toList(), class1.tsym); |
2766 |
} |
|
2767 |
||
2768 |
/** |
|
2769 |
* Return the minimum type of a closure, a compound type if no |
|
2770 |
* unique minimum exists. |
|
2771 |
*/ |
|
2772 |
private Type compoundMin(List<Type> cl) { |
|
2773 |
if (cl.isEmpty()) return syms.objectType; |
|
2774 |
List<Type> compound = closureMin(cl); |
|
2775 |
if (compound.isEmpty()) |
|
2776 |
return null; |
|
2777 |
else if (compound.tail.isEmpty()) |
|
2778 |
return compound.head; |
|
2779 |
else |
|
2780 |
return makeCompoundType(compound); |
|
2781 |
} |
|
2782 |
||
2783 |
/** |
|
2784 |
* Return the minimum types of a closure, suitable for computing |
|
2785 |
* compoundMin or glb. |
|
2786 |
*/ |
|
2787 |
private List<Type> closureMin(List<Type> cl) { |
|
2788 |
ListBuffer<Type> classes = lb(); |
|
2789 |
ListBuffer<Type> interfaces = lb(); |
|
2790 |
while (!cl.isEmpty()) { |
|
2791 |
Type current = cl.head; |
|
2792 |
if (current.isInterface()) |
|
2793 |
interfaces.append(current); |
|
2794 |
else |
|
2795 |
classes.append(current); |
|
2796 |
ListBuffer<Type> candidates = lb(); |
|
2797 |
for (Type t : cl.tail) { |
|
2798 |
if (!isSubtypeNoCapture(current, t)) |
|
2799 |
candidates.append(t); |
|
2800 |
} |
|
2801 |
cl = candidates.toList(); |
|
2802 |
} |
|
2803 |
return classes.appendList(interfaces).toList(); |
|
2804 |
} |
|
2805 |
||
2806 |
/** |
|
2807 |
* Return the least upper bound of pair of types. if the lub does |
|
2808 |
* not exist return null. |
|
2809 |
*/ |
|
2810 |
public Type lub(Type t1, Type t2) { |
|
2811 |
return lub(List.of(t1, t2)); |
|
2812 |
} |
|
2813 |
||
2814 |
/** |
|
2815 |
* Return the least upper bound (lub) of set of types. If the lub |
|
2816 |
* does not exist return the type of null (bottom). |
|
2817 |
*/ |
|
2818 |
public Type lub(List<Type> ts) { |
|
2819 |
final int ARRAY_BOUND = 1; |
|
2820 |
final int CLASS_BOUND = 2; |
|
2821 |
int boundkind = 0; |
|
2822 |
for (Type t : ts) { |
|
2823 |
switch (t.tag) { |
|
2824 |
case CLASS: |
|
2825 |
boundkind |= CLASS_BOUND; |
|
2826 |
break; |
|
2827 |
case ARRAY: |
|
2828 |
boundkind |= ARRAY_BOUND; |
|
2829 |
break; |
|
2830 |
case TYPEVAR: |
|
2831 |
do { |
|
2832 |
t = t.getUpperBound(); |
|
2833 |
} while (t.tag == TYPEVAR); |
|
2834 |
if (t.tag == ARRAY) { |
|
2835 |
boundkind |= ARRAY_BOUND; |
|
2836 |
} else { |
|
2837 |
boundkind |= CLASS_BOUND; |
|
2838 |
} |
|
2839 |
break; |
|
2840 |
default: |
|
2841 |
if (t.isPrimitive()) |
|
162
6620f2a8e265
6611449: Internal Error thrown during generic method/constructor invocation
mcimadamore
parents:
10
diff
changeset
|
2842 |
return syms.errType; |
10 | 2843 |
} |
2844 |
} |
|
2845 |
switch (boundkind) { |
|
2846 |
case 0: |
|
2847 |
return syms.botType; |
|
2848 |
||
2849 |
case ARRAY_BOUND: |
|
2850 |
// calculate lub(A[], B[]) |
|
2851 |
List<Type> elements = Type.map(ts, elemTypeFun); |
|
2852 |
for (Type t : elements) { |
|
2853 |
if (t.isPrimitive()) { |
|
2854 |
// if a primitive type is found, then return |
|
2855 |
// arraySuperType unless all the types are the |
|
2856 |
// same |
|
2857 |
Type first = ts.head; |
|
2858 |
for (Type s : ts.tail) { |
|
2859 |
if (!isSameType(first, s)) { |
|
2860 |
// lub(int[], B[]) is Cloneable & Serializable |
|
2861 |
return arraySuperType(); |
|
2862 |
} |
|
2863 |
} |
|
2864 |
// all the array types are the same, return one |
|
2865 |
// lub(int[], int[]) is int[] |
|
2866 |
return first; |
|
2867 |
} |
|
2868 |
} |
|
2869 |
// lub(A[], B[]) is lub(A, B)[] |
|
2870 |
return new ArrayType(lub(elements), syms.arrayClass); |
|
2871 |
||
2872 |
case CLASS_BOUND: |
|
2873 |
// calculate lub(A, B) |
|
2874 |
while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR) |
|
2875 |
ts = ts.tail; |
|
8032 | 2876 |
Assert.check(!ts.isEmpty()); |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2877 |
//step 1 - compute erased candidate set (EC) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2878 |
List<Type> cl = erasedSupertypes(ts.head); |
10 | 2879 |
for (Type t : ts.tail) { |
2880 |
if (t.tag == CLASS || t.tag == TYPEVAR) |
|
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2881 |
cl = intersect(cl, erasedSupertypes(t)); |
10 | 2882 |
} |
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2883 |
//step 2 - compute minimal erased candidate set (MEC) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2884 |
List<Type> mec = closureMin(cl); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2885 |
//step 3 - for each element G in MEC, compute lci(Inv(G)) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2886 |
List<Type> candidates = List.nil(); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2887 |
for (Type erasedSupertype : mec) { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2888 |
List<Type> lci = List.of(asSuper(ts.head, erasedSupertype.tsym)); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2889 |
for (Type t : ts) { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2890 |
lci = intersect(lci, List.of(asSuper(t, erasedSupertype.tsym))); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2891 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2892 |
candidates = candidates.appendList(lci); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2893 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2894 |
//step 4 - let MEC be { G1, G2 ... Gn }, then we have that |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2895 |
//lub = lci(Inv(G1)) & lci(Inv(G2)) & ... & lci(Inv(Gn)) |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2896 |
return compoundMin(candidates); |
10 | 2897 |
|
2898 |
default: |
|
2899 |
// calculate lub(A, B[]) |
|
2900 |
List<Type> classes = List.of(arraySuperType()); |
|
2901 |
for (Type t : ts) { |
|
2902 |
if (t.tag != ARRAY) // Filter out any arrays |
|
2903 |
classes = classes.prepend(t); |
|
2904 |
} |
|
2905 |
// lub(A, B[]) is lub(A, arraySuperType) |
|
2906 |
return lub(classes); |
|
2907 |
} |
|
2908 |
} |
|
2909 |
// where |
|
8617
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2910 |
List<Type> erasedSupertypes(Type t) { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2911 |
ListBuffer<Type> buf = lb(); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2912 |
for (Type sup : closure(t)) { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2913 |
if (sup.tag == TYPEVAR) { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2914 |
buf.append(sup); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2915 |
} else { |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2916 |
buf.append(erasure(sup)); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2917 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2918 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2919 |
return buf.toList(); |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2920 |
} |
6a05d1669247
7015715: lub gets stuck on type with complex supertype
mcimadamore
parents:
8430
diff
changeset
|
2921 |
|
10 | 2922 |
private Type arraySuperType = null; |
2923 |
private Type arraySuperType() { |
|
2924 |
// initialized lazily to avoid problems during compiler startup |
|
2925 |
if (arraySuperType == null) { |
|
2926 |
synchronized (this) { |
|
2927 |
if (arraySuperType == null) { |
|
2928 |
// JLS 10.8: all arrays implement Cloneable and Serializable. |
|
2929 |
arraySuperType = makeCompoundType(List.of(syms.serializableType, |
|
2930 |
syms.cloneableType), |
|
2931 |
syms.objectType); |
|
2932 |
} |
|
2933 |
} |
|
2934 |
} |
|
2935 |
return arraySuperType; |
|
2936 |
} |
|
2937 |
// </editor-fold> |
|
2938 |
||
2939 |
// <editor-fold defaultstate="collapsed" desc="Greatest lower bound"> |
|
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2940 |
public Type glb(List<Type> ts) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2941 |
Type t1 = ts.head; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2942 |
for (Type t2 : ts.tail) { |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2943 |
if (t1.isErroneous()) |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2944 |
return t1; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2945 |
t1 = glb(t1, t2); |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2946 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2947 |
return t1; |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2948 |
} |
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1874
diff
changeset
|
2949 |
//where |
10 | 2950 |
public Type glb(Type t, Type s) { |
2951 |
if (s == null) |
|
2952 |
return t; |
|
7331
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
2953 |
else if (t.isPrimitive() || s.isPrimitive()) |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
2954 |
return syms.errType; |
10 | 2955 |
else if (isSubtypeNoCapture(t, s)) |
2956 |
return t; |
|
2957 |
else if (isSubtypeNoCapture(s, t)) |
|
2958 |
return s; |
|
2959 |
||
2960 |
List<Type> closure = union(closure(t), closure(s)); |
|
2961 |
List<Type> bounds = closureMin(closure); |
|
2962 |
||
2963 |
if (bounds.isEmpty()) { // length == 0 |
|
2964 |
return syms.objectType; |
|
2965 |
} else if (bounds.tail.isEmpty()) { // length == 1 |
|
2966 |
return bounds.head; |
|
2967 |
} else { // length > 1 |
|
2968 |
int classCount = 0; |
|
2969 |
for (Type bound : bounds) |
|
2970 |
if (!bound.isInterface()) |
|
2971 |
classCount++; |
|
2972 |
if (classCount > 1) |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
2973 |
return createErrorType(t); |
10 | 2974 |
} |
2975 |
return makeCompoundType(bounds); |
|
2976 |
} |
|
2977 |
// </editor-fold> |
|
2978 |
||
2979 |
// <editor-fold defaultstate="collapsed" desc="hashCode"> |
|
2980 |
/** |
|
2981 |
* Compute a hash code on a type. |
|
2982 |
*/ |
|
2983 |
public static int hashCode(Type t) { |
|
2984 |
return hashCode.visit(t); |
|
2985 |
} |
|
2986 |
// where |
|
2987 |
private static final UnaryVisitor<Integer> hashCode = new UnaryVisitor<Integer>() { |
|
2988 |
||
2989 |
public Integer visitType(Type t, Void ignored) { |
|
2990 |
return t.tag; |
|
2991 |
} |
|
2992 |
||
2993 |
@Override |
|
2994 |
public Integer visitClassType(ClassType t, Void ignored) { |
|
2995 |
int result = visit(t.getEnclosingType()); |
|
2996 |
result *= 127; |
|
2997 |
result += t.tsym.flatName().hashCode(); |
|
2998 |
for (Type s : t.getTypeArguments()) { |
|
2999 |
result *= 127; |
|
3000 |
result += visit(s); |
|
3001 |
} |
|
3002 |
return result; |
|
3003 |
} |
|
3004 |
||
3005 |
@Override |
|
3006 |
public Integer visitWildcardType(WildcardType t, Void ignored) { |
|
3007 |
int result = t.kind.hashCode(); |
|
3008 |
if (t.type != null) { |
|
3009 |
result *= 127; |
|
3010 |
result += visit(t.type); |
|
3011 |
} |
|
3012 |
return result; |
|
3013 |
} |
|
3014 |
||
3015 |
@Override |
|
3016 |
public Integer visitArrayType(ArrayType t, Void ignored) { |
|
3017 |
return visit(t.elemtype) + 12; |
|
3018 |
} |
|
3019 |
||
3020 |
@Override |
|
3021 |
public Integer visitTypeVar(TypeVar t, Void ignored) { |
|
3022 |
return System.identityHashCode(t.tsym); |
|
3023 |
} |
|
3024 |
||
3025 |
@Override |
|
3026 |
public Integer visitUndetVar(UndetVar t, Void ignored) { |
|
3027 |
return System.identityHashCode(t); |
|
3028 |
} |
|
3029 |
||
3030 |
@Override |
|
3031 |
public Integer visitErrorType(ErrorType t, Void ignored) { |
|
3032 |
return 0; |
|
3033 |
} |
|
3034 |
}; |
|
3035 |
// </editor-fold> |
|
3036 |
||
3037 |
// <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable"> |
|
3038 |
/** |
|
3039 |
* Does t have a result that is a subtype of the result type of s, |
|
3040 |
* suitable for covariant returns? It is assumed that both types |
|
3041 |
* are (possibly polymorphic) method types. Monomorphic method |
|
3042 |
* types are handled in the obvious way. Polymorphic method types |
|
3043 |
* require renaming all type variables of one to corresponding |
|
3044 |
* type variables in the other, where correspondence is by |
|
3045 |
* position in the type parameter list. */ |
|
3046 |
public boolean resultSubtype(Type t, Type s, Warner warner) { |
|
3047 |
List<Type> tvars = t.getTypeArguments(); |
|
3048 |
List<Type> svars = s.getTypeArguments(); |
|
3049 |
Type tres = t.getReturnType(); |
|
3050 |
Type sres = subst(s.getReturnType(), svars, tvars); |
|
3051 |
return covariantReturnType(tres, sres, warner); |
|
3052 |
} |
|
3053 |
||
3054 |
/** |
|
3055 |
* Return-Type-Substitutable. |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
3056 |
* @jls section 8.4.5 |
10 | 3057 |
*/ |
3058 |
public boolean returnTypeSubstitutable(Type r1, Type r2) { |
|
3059 |
if (hasSameArgs(r1, r2)) |
|
1874 | 3060 |
return resultSubtype(r1, r2, Warner.noWarnings); |
10 | 3061 |
else |
3062 |
return covariantReturnType(r1.getReturnType(), |
|
1874 | 3063 |
erasure(r2.getReturnType()), |
3064 |
Warner.noWarnings); |
|
3065 |
} |
|
3066 |
||
3067 |
public boolean returnTypeSubstitutable(Type r1, |
|
3068 |
Type r2, Type r2res, |
|
3069 |
Warner warner) { |
|
3070 |
if (isSameType(r1.getReturnType(), r2res)) |
|
3071 |
return true; |
|
3072 |
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive()) |
|
3073 |
return false; |
|
3074 |
||
3075 |
if (hasSameArgs(r1, r2)) |
|
3076 |
return covariantReturnType(r1.getReturnType(), r2res, warner); |
|
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
3077 |
if (!allowCovariantReturns) |
1874 | 3078 |
return false; |
3079 |
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner)) |
|
3080 |
return true; |
|
3081 |
if (!isSubtype(r1.getReturnType(), erasure(r2res))) |
|
3082 |
return false; |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
3083 |
warner.warn(LintCategory.UNCHECKED); |
1874 | 3084 |
return true; |
10 | 3085 |
} |
3086 |
||
3087 |
/** |
|
3088 |
* Is t an appropriate return type in an overrider for a |
|
3089 |
* method that returns s? |
|
3090 |
*/ |
|
3091 |
public boolean covariantReturnType(Type t, Type s, Warner warner) { |
|
1874 | 3092 |
return |
3093 |
isSameType(t, s) || |
|
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
3094 |
allowCovariantReturns && |
10 | 3095 |
!t.isPrimitive() && |
1874 | 3096 |
!s.isPrimitive() && |
3097 |
isAssignable(t, s, warner); |
|
10 | 3098 |
} |
3099 |
// </editor-fold> |
|
3100 |
||
3101 |
// <editor-fold defaultstate="collapsed" desc="Box/unbox support"> |
|
3102 |
/** |
|
3103 |
* Return the class that boxes the given primitive. |
|
3104 |
*/ |
|
3105 |
public ClassSymbol boxedClass(Type t) { |
|
3106 |
return reader.enterClass(syms.boxedName[t.tag]); |
|
3107 |
} |
|
3108 |
||
3109 |
/** |
|
7331
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3110 |
* Return the boxed type if 't' is primitive, otherwise return 't' itself. |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3111 |
*/ |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3112 |
public Type boxedTypeOrType(Type t) { |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3113 |
return t.isPrimitive() ? |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3114 |
boxedClass(t).type : |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3115 |
t; |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3116 |
} |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3117 |
|
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
7204
diff
changeset
|
3118 |
/** |
10 | 3119 |
* Return the primitive type corresponding to a boxed type. |
3120 |
*/ |
|
3121 |
public Type unboxedType(Type t) { |
|
3122 |
if (allowBoxing) { |
|
3123 |
for (int i=0; i<syms.boxedName.length; i++) { |
|
3124 |
Name box = syms.boxedName[i]; |
|
3125 |
if (box != null && |
|
3126 |
asSuper(t, reader.enterClass(box)) != null) |
|
3127 |
return syms.typeOfTag[i]; |
|
3128 |
} |
|
3129 |
} |
|
3130 |
return Type.noType; |
|
3131 |
} |
|
3132 |
// </editor-fold> |
|
3133 |
||
3134 |
// <editor-fold defaultstate="collapsed" desc="Capture conversion"> |
|
3135 |
/* |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
3136 |
* JLS 5.1.10 Capture Conversion: |
10 | 3137 |
* |
3138 |
* Let G name a generic type declaration with n formal type |
|
3139 |
* parameters A1 ... An with corresponding bounds U1 ... Un. There |
|
3140 |
* exists a capture conversion from G<T1 ... Tn> to G<S1 ... Sn>, |
|
3141 |
* where, for 1 <= i <= n: |
|
3142 |
* |
|
3143 |
* + If Ti is a wildcard type argument (4.5.1) of the form ? then |
|
3144 |
* Si is a fresh type variable whose upper bound is |
|
3145 |
* Ui[A1 := S1, ..., An := Sn] and whose lower bound is the null |
|
3146 |
* type. |
|
3147 |
* |
|
3148 |
* + If Ti is a wildcard type argument of the form ? extends Bi, |
|
3149 |
* then Si is a fresh type variable whose upper bound is |
|
3150 |
* glb(Bi, Ui[A1 := S1, ..., An := Sn]) and whose lower bound is |
|
3151 |
* the null type, where glb(V1,... ,Vm) is V1 & ... & Vm. It is |
|
3152 |
* a compile-time error if for any two classes (not interfaces) |
|
3153 |
* Vi and Vj,Vi is not a subclass of Vj or vice versa. |
|
3154 |
* |
|
3155 |
* + If Ti is a wildcard type argument of the form ? super Bi, |
|
3156 |
* then Si is a fresh type variable whose upper bound is |
|
3157 |
* Ui[A1 := S1, ..., An := Sn] and whose lower bound is Bi. |
|
3158 |
* |
|
3159 |
* + Otherwise, Si = Ti. |
|
3160 |
* |
|
3161 |
* Capture conversion on any type other than a parameterized type |
|
3162 |
* (4.5) acts as an identity conversion (5.1.1). Capture |
|
3163 |
* conversions never require a special action at run time and |
|
3164 |
* therefore never throw an exception at run time. |
|
3165 |
* |
|
3166 |
* Capture conversion is not applied recursively. |
|
3167 |
*/ |
|
3168 |
/** |
|
9303
eae35c201e19
7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents:
9301
diff
changeset
|
3169 |
* Capture conversion as specified by the JLS. |
10 | 3170 |
*/ |
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3171 |
|
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3172 |
public List<Type> capture(List<Type> ts) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3173 |
List<Type> buf = List.nil(); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3174 |
for (Type t : ts) { |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3175 |
buf = buf.prepend(capture(t)); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3176 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3177 |
return buf.reverse(); |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
2223
diff
changeset
|
3178 |
} |
10 | 3179 |
public Type capture(Type t) { |
3180 |
if (t.tag != CLASS) |
|
3181 |
return t; |
|
6350
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3182 |
if (t.getEnclosingType() != Type.noType) { |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3183 |
Type capturedEncl = capture(t.getEnclosingType()); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3184 |
if (capturedEncl != t.getEnclosingType()) { |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3185 |
Type type1 = memberType(capturedEncl, t.tsym); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3186 |
t = subst(type1, t.tsym.type.getTypeArguments(), t.getTypeArguments()); |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3187 |
} |
7070b0722ebb
6886247: regression: javac crashes with an assertion error in Attr.java
mcimadamore
parents:
5847
diff
changeset
|
3188 |
} |
10 | 3189 |
ClassType cls = (ClassType)t; |
3190 |
if (cls.isRaw() || !cls.isParameterized()) |
|
3191 |
return cls; |
|
3192 |
||
3193 |
ClassType G = (ClassType)cls.asElement().asType(); |
|
3194 |
List<Type> A = G.getTypeArguments(); |
|
3195 |
List<Type> T = cls.getTypeArguments(); |
|
3196 |
List<Type> S = freshTypeVariables(T); |
|
3197 |
||
3198 |
List<Type> currentA = A; |
|
3199 |
List<Type> currentT = T; |
|
3200 |
List<Type> currentS = S; |
|
3201 |
boolean captured = false; |
|
3202 |
while (!currentA.isEmpty() && |
|
3203 |
!currentT.isEmpty() && |
|
3204 |
!currentS.isEmpty()) { |
|
3205 |
if (currentS.head != currentT.head) { |
|
3206 |
captured = true; |
|
3207 |
WildcardType Ti = (WildcardType)currentT.head; |
|
3208 |
Type Ui = currentA.head.getUpperBound(); |
|
3209 |
CapturedType Si = (CapturedType)currentS.head; |
|
3210 |
if (Ui == null) |
|
3211 |
Ui = syms.objectType; |
|
3212 |
switch (Ti.kind) { |
|
3213 |
case UNBOUND: |
|
3214 |
Si.bound = subst(Ui, A, S); |
|
3215 |
Si.lower = syms.botType; |
|
3216 |
break; |
|
3217 |
case EXTENDS: |
|
3218 |
Si.bound = glb(Ti.getExtendsBound(), subst(Ui, A, S)); |
|
3219 |
Si.lower = syms.botType; |
|
3220 |
break; |
|
3221 |
case SUPER: |
|
3222 |
Si.bound = subst(Ui, A, S); |
|
3223 |
Si.lower = Ti.getSuperBound(); |
|
3224 |
break; |
|
3225 |
} |
|
3226 |
if (Si.bound == Si.lower) |
|
3227 |
currentS.head = Si.bound; |
|
3228 |
} |
|
3229 |
currentA = currentA.tail; |
|
3230 |
currentT = currentT.tail; |
|
3231 |
currentS = currentS.tail; |
|
3232 |
} |
|
3233 |
if (!currentA.isEmpty() || !currentT.isEmpty() || !currentS.isEmpty()) |
|
3234 |
return erasure(t); // some "rare" type involved |
|
3235 |
||
3236 |
if (captured) |
|
3237 |
return new ClassType(cls.getEnclosingType(), S, cls.tsym); |
|
3238 |
else |
|
3239 |
return t; |
|
3240 |
} |
|
3241 |
// where |
|
2221
cd6557bcaa0a
6799605: Basic/Raw formatters should use type/symbol printer instead of toString()
mcimadamore
parents:
2218
diff
changeset
|
3242 |
public List<Type> freshTypeVariables(List<Type> types) { |
10 | 3243 |
ListBuffer<Type> result = lb(); |
3244 |
for (Type t : types) { |
|
3245 |
if (t.tag == WILDCARD) { |
|
3246 |
Type bound = ((WildcardType)t).getExtendsBound(); |
|
3247 |
if (bound == null) |
|
3248 |
bound = syms.objectType; |
|
3249 |
result.append(new CapturedType(capturedName, |
|
3250 |
syms.noSymbol, |
|
3251 |
bound, |
|
3252 |
syms.botType, |
|
3253 |
(WildcardType)t)); |
|
3254 |
} else { |
|
3255 |
result.append(t); |
|
3256 |
} |
|
3257 |
} |
|
3258 |
return result.toList(); |
|
3259 |
} |
|
3260 |
// </editor-fold> |
|
3261 |
||
3262 |
// <editor-fold defaultstate="collapsed" desc="Internal utility methods"> |
|
3263 |
private List<Type> upperBounds(List<Type> ss) { |
|
3264 |
if (ss.isEmpty()) return ss; |
|
3265 |
Type head = upperBound(ss.head); |
|
3266 |
List<Type> tail = upperBounds(ss.tail); |
|
3267 |
if (head != ss.head || tail != ss.tail) |
|
3268 |
return tail.prepend(head); |
|
3269 |
else |
|
3270 |
return ss; |
|
3271 |
} |
|
3272 |
||
3273 |
private boolean sideCast(Type from, Type to, Warner warn) { |
|
3274 |
// We are casting from type $from$ to type $to$, which are |
|
3275 |
// non-final unrelated types. This method |
|
3276 |
// tries to reject a cast by transferring type parameters |
|
3277 |
// from $to$ to $from$ by common superinterfaces. |
|
3278 |
boolean reverse = false; |
|
3279 |
Type target = to; |
|
3280 |
if ((to.tsym.flags() & INTERFACE) == 0) { |
|
8032 | 3281 |
Assert.check((from.tsym.flags() & INTERFACE) != 0); |
10 | 3282 |
reverse = true; |
3283 |
to = from; |
|
3284 |
from = target; |
|
3285 |
} |
|
3286 |
List<Type> commonSupers = superClosure(to, erasure(from)); |
|
3287 |
boolean giveWarning = commonSupers.isEmpty(); |
|
3288 |
// The arguments to the supers could be unified here to |
|
3289 |
// get a more accurate analysis |
|
3290 |
while (commonSupers.nonEmpty()) { |
|
3291 |
Type t1 = asSuper(from, commonSupers.head.tsym); |
|
3292 |
Type t2 = commonSupers.head; // same as asSuper(to, commonSupers.head.tsym); |
|
3293 |
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments())) |
|
3294 |
return false; |
|
3295 |
giveWarning = giveWarning || (reverse ? giveWarning(t2, t1) : giveWarning(t1, t2)); |
|
3296 |
commonSupers = commonSupers.tail; |
|
3297 |
} |
|
1792 | 3298 |
if (giveWarning && !isReifiable(reverse ? from : to)) |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
3299 |
warn.warn(LintCategory.UNCHECKED); |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
3300 |
if (!allowCovariantReturns) |
10 | 3301 |
// reject if there is a common method signature with |
3302 |
// incompatible return types. |
|
3303 |
chk.checkCompatibleAbstracts(warn.pos(), from, to); |
|
3304 |
return true; |
|
3305 |
} |
|
3306 |
||
3307 |
private boolean sideCastFinal(Type from, Type to, Warner warn) { |
|
3308 |
// We are casting from type $from$ to type $to$, which are |
|
3309 |
// unrelated types one of which is final and the other of |
|
3310 |
// which is an interface. This method |
|
3311 |
// tries to reject a cast by transferring type parameters |
|
3312 |
// from the final class to the interface. |
|
3313 |
boolean reverse = false; |
|
3314 |
Type target = to; |
|
3315 |
if ((to.tsym.flags() & INTERFACE) == 0) { |
|
8032 | 3316 |
Assert.check((from.tsym.flags() & INTERFACE) != 0); |
10 | 3317 |
reverse = true; |
3318 |
to = from; |
|
3319 |
from = target; |
|
3320 |
} |
|
8032 | 3321 |
Assert.check((from.tsym.flags() & FINAL) != 0); |
10 | 3322 |
Type t1 = asSuper(from, to.tsym); |
3323 |
if (t1 == null) return false; |
|
3324 |
Type t2 = to; |
|
3325 |
if (disjointTypes(t1.getTypeArguments(), t2.getTypeArguments())) |
|
3326 |
return false; |
|
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9303
diff
changeset
|
3327 |
if (!allowCovariantReturns) |
10 | 3328 |
// reject if there is a common method signature with |
3329 |
// incompatible return types. |
|
3330 |
chk.checkCompatibleAbstracts(warn.pos(), from, to); |
|
3331 |
if (!isReifiable(target) && |
|
3332 |
(reverse ? giveWarning(t2, t1) : giveWarning(t1, t2))) |
|
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7637
diff
changeset
|
3333 |
warn.warn(LintCategory.UNCHECKED); |
10 | 3334 |
return true; |
3335 |
} |
|
3336 |
||
3337 |
private boolean giveWarning(Type from, Type to) { |
|
2218
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
3338 |
Type subFrom = asSub(from, to.tsym); |
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
3339 |
return to.isParameterized() && |
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
3340 |
(!(isUnbounded(to) || |
a8ec0baae870
6467183: javac fails to raise unchecked warning on cast of parameterized generic subclass
mcimadamore
parents:
1993
diff
changeset
|
3341 |
isSubtype(from, to) || |
7204
0960f7e5e366
6714835: Safe cast is rejected (with warning) by javac
mcimadamore
parents:
6709
diff
changeset
|
3342 |
((subFrom != null) && containsType(to.allparams(), subFrom.allparams())))); |
10 | 3343 |
} |
3344 |
||
3345 |
private List<Type> superClosure(Type t, Type s) { |
|
3346 |
List<Type> cl = List.nil(); |
|
3347 |
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |
|
3348 |
if (isSubtype(s, erasure(l.head))) { |
|
3349 |
cl = insert(cl, l.head); |
|
3350 |
} else { |
|
3351 |
cl = union(cl, superClosure(l.head, s)); |
|
3352 |
} |
|
3353 |
} |
|
3354 |
return cl; |
|
3355 |
} |
|
3356 |
||
3357 |
private boolean containsTypeEquivalent(Type t, Type s) { |
|
3358 |
return |
|
3359 |
isSameType(t, s) || // shortcut |
|
3360 |
containsType(t, s) && containsType(s, t); |
|
3361 |
} |
|
3362 |
||
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3363 |
// <editor-fold defaultstate="collapsed" desc="adapt"> |
10 | 3364 |
/** |
3365 |
* Adapt a type by computing a substitution which maps a source |
|
3366 |
* type to a target type. |
|
3367 |
* |
|
3368 |
* @param source the source type |
|
3369 |
* @param target the target type |
|
3370 |
* @param from the type variables of the computed substitution |
|
3371 |
* @param to the types of the computed substitution. |
|
3372 |
*/ |
|
3373 |
public void adapt(Type source, |
|
3374 |
Type target, |
|
3375 |
ListBuffer<Type> from, |
|
3376 |
ListBuffer<Type> to) throws AdaptFailure { |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3377 |
new Adapter(from, to).adapt(source, target); |
10 | 3378 |
} |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3379 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3380 |
class Adapter extends SimpleVisitor<Void, Type> { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3381 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3382 |
ListBuffer<Type> from; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3383 |
ListBuffer<Type> to; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3384 |
Map<Symbol,Type> mapping; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3385 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3386 |
Adapter(ListBuffer<Type> from, ListBuffer<Type> to) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3387 |
this.from = from; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3388 |
this.to = to; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3389 |
mapping = new HashMap<Symbol,Type>(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3390 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3391 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3392 |
public void adapt(Type source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3393 |
visit(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3394 |
List<Type> fromList = from.toList(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3395 |
List<Type> toList = to.toList(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3396 |
while (!fromList.isEmpty()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3397 |
Type val = mapping.get(fromList.head.tsym); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3398 |
if (toList.head != val) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3399 |
toList.head = val; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3400 |
fromList = fromList.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3401 |
toList = toList.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3402 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3403 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3404 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3405 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3406 |
public Void visitClassType(ClassType source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3407 |
if (target.tag == CLASS) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3408 |
adaptRecursive(source.allparams(), target.allparams()); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3409 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3410 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3411 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3412 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3413 |
public Void visitArrayType(ArrayType source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3414 |
if (target.tag == ARRAY) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3415 |
adaptRecursive(elemtype(source), elemtype(target)); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3416 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3417 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3418 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3419 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3420 |
public Void visitWildcardType(WildcardType source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3421 |
if (source.isExtendsBound()) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3422 |
adaptRecursive(upperBound(source), upperBound(target)); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3423 |
else if (source.isSuperBound()) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3424 |
adaptRecursive(lowerBound(source), lowerBound(target)); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3425 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3426 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3427 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3428 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3429 |
public Void visitTypeVar(TypeVar source, Type target) throws AdaptFailure { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3430 |
// Check to see if there is |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3431 |
// already a mapping for $source$, in which case |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3432 |
// the old mapping will be merged with the new |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3433 |
Type val = mapping.get(source.tsym); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3434 |
if (val != null) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3435 |
if (val.isSuperBound() && target.isSuperBound()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3436 |
val = isSubtype(lowerBound(val), lowerBound(target)) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3437 |
? target : val; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3438 |
} else if (val.isExtendsBound() && target.isExtendsBound()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3439 |
val = isSubtype(upperBound(val), upperBound(target)) |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3440 |
? val : target; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3441 |
} else if (!isSameType(val, target)) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3442 |
throw new AdaptFailure(); |
10 | 3443 |
} |
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3444 |
} else { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3445 |
val = target; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3446 |
from.append(source); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3447 |
to.append(target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3448 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3449 |
mapping.put(source.tsym, val); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3450 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3451 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3452 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3453 |
@Override |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3454 |
public Void visitType(Type source, Type target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3455 |
return null; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3456 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3457 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3458 |
private Set<TypePair> cache = new HashSet<TypePair>(); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3459 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3460 |
private void adaptRecursive(Type source, Type target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3461 |
TypePair pair = new TypePair(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3462 |
if (cache.add(pair)) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3463 |
try { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3464 |
visit(source, target); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3465 |
} finally { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3466 |
cache.remove(pair); |
10 | 3467 |
} |
3468 |
} |
|
3469 |
} |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3470 |
|
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3471 |
private void adaptRecursive(List<Type> source, List<Type> target) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3472 |
if (source.length() == target.length()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3473 |
while (source.nonEmpty()) { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3474 |
adaptRecursive(source.head, target.head); |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3475 |
source = source.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3476 |
target = target.tail; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3477 |
} |
10 | 3478 |
} |
3479 |
} |
|
3480 |
} |
|
3481 |
||
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3482 |
public static class AdaptFailure extends RuntimeException { |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3483 |
static final long serialVersionUID = -7490231548272701566L; |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3484 |
} |
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3485 |
|
10 | 3486 |
private void adaptSelf(Type t, |
3487 |
ListBuffer<Type> from, |
|
3488 |
ListBuffer<Type> to) { |
|
3489 |
try { |
|
3490 |
//if (t.tsym.type != t) |
|
3491 |
adapt(t.tsym.type, t, from, to); |
|
3492 |
} catch (AdaptFailure ex) { |
|
3493 |
// Adapt should never fail calculating a mapping from |
|
3494 |
// t.tsym.type to t as there can be no merge problem. |
|
3495 |
throw new AssertionError(ex); |
|
3496 |
} |
|
3497 |
} |
|
1473
16ba23bb25e6
6586091: javac crashes with StackOverflowError
mcimadamore
parents:
1471
diff
changeset
|
3498 |
// </editor-fold> |
10 | 3499 |
|
3500 |
/** |
|
3501 |
* Rewrite all type variables (universal quantifiers) in the given |
|
3502 |
* type to wildcards (existential quantifiers). This is used to |
|
3503 |
* determine if a cast is allowed. For example, if high is true |
|
3504 |
* and {@code T <: Number}, then {@code List<T>} is rewritten to |
|
3505 |
* {@code List<? extends Number>}. Since {@code List<Integer> <: |
|
3506 |
* List<? extends Number>} a {@code List<T>} can be cast to {@code |
|
3507 |
* List<Integer>} with a warning. |
|
3508 |
* @param t a type |
|
3509 |
* @param high if true return an upper bound; otherwise a lower |
|
3510 |
* bound |
|
3511 |
* @param rewriteTypeVars only rewrite captured wildcards if false; |
|
3512 |
* otherwise rewrite all type variables |
|
3513 |
* @return the type rewritten with wildcards (existential |
|
3514 |
* quantifiers) only |
|
3515 |
*/ |
|
3516 |
private Type rewriteQuantifiers(Type t, boolean high, boolean rewriteTypeVars) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3517 |
return new Rewriter(high, rewriteTypeVars).visit(t); |
1530 | 3518 |
} |
3519 |
||
3520 |
class Rewriter extends UnaryVisitor<Type> { |
|
3521 |
||
3522 |
boolean high; |
|
3523 |
boolean rewriteTypeVars; |
|
3524 |
||
3525 |
Rewriter(boolean high, boolean rewriteTypeVars) { |
|
3526 |
this.high = high; |
|
3527 |
this.rewriteTypeVars = rewriteTypeVars; |
|
3528 |
} |
|
3529 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3530 |
@Override |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3531 |
public Type visitClassType(ClassType t, Void s) { |
1530 | 3532 |
ListBuffer<Type> rewritten = new ListBuffer<Type>(); |
3533 |
boolean changed = false; |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3534 |
for (Type arg : t.allparams()) { |
1530 | 3535 |
Type bound = visit(arg); |
3536 |
if (arg != bound) { |
|
3537 |
changed = true; |
|
3538 |
} |
|
3539 |
rewritten.append(bound); |
|
10 | 3540 |
} |
1530 | 3541 |
if (changed) |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3542 |
return subst(t.tsym.type, |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3543 |
t.tsym.type.allparams(), |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3544 |
rewritten.toList()); |
1530 | 3545 |
else |
3546 |
return t; |
|
3547 |
} |
|
3548 |
||
3549 |
public Type visitType(Type t, Void s) { |
|
3550 |
return high ? upperBound(t) : lowerBound(t); |
|
3551 |
} |
|
3552 |
||
3553 |
@Override |
|
3554 |
public Type visitCapturedType(CapturedType t, Void s) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3555 |
Type bound = visitWildcardType(t.wildcard, null); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3556 |
return (bound.contains(t)) ? |
7627
de2a86da165e
7005095: Cast: compile reject sensible cast from final class to interface
mcimadamore
parents:
7331
diff
changeset
|
3557 |
erasure(bound) : |
de2a86da165e
7005095: Cast: compile reject sensible cast from final class to interface
mcimadamore
parents:
7331
diff
changeset
|
3558 |
bound; |
10 | 3559 |
} |
1530 | 3560 |
|
3561 |
@Override |
|
3562 |
public Type visitTypeVar(TypeVar t, Void s) { |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3563 |
if (rewriteTypeVars) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3564 |
Type bound = high ? |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3565 |
(t.bound.contains(t) ? |
7627
de2a86da165e
7005095: Cast: compile reject sensible cast from final class to interface
mcimadamore
parents:
7331
diff
changeset
|
3566 |
erasure(t.bound) : |
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3567 |
visit(t.bound)) : |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3568 |
syms.botType; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3569 |
return rewriteAsWildcardType(bound, t); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3570 |
} |
1530 | 3571 |
else |
3572 |
return t; |
|
3573 |
} |
|
3574 |
||
3575 |
@Override |
|
3576 |
public Type visitWildcardType(WildcardType t, Void s) { |
|
3577 |
Type bound = high ? t.getExtendsBound() : |
|
3578 |
t.getSuperBound(); |
|
3579 |
if (bound == null) |
|
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3580 |
bound = high ? syms.objectType : syms.botType; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3581 |
return rewriteAsWildcardType(visit(bound), t.bound); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3582 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3583 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3584 |
private Type rewriteAsWildcardType(Type bound, TypeVar formal) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3585 |
return high ? |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3586 |
makeExtendsWildcard(B(bound), formal) : |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3587 |
makeSuperWildcard(B(bound), formal); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3588 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3589 |
|
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3590 |
Type B(Type t) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3591 |
while (t.tag == WILDCARD) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3592 |
WildcardType w = (WildcardType)t; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3593 |
t = high ? |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3594 |
w.getExtendsBound() : |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3595 |
w.getSuperBound(); |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3596 |
if (t == null) { |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3597 |
t = high ? syms.objectType : syms.botType; |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3598 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3599 |
} |
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3600 |
return t; |
1530 | 3601 |
} |
10 | 3602 |
} |
3603 |
||
6353
bb5c39054bf3
6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents:
6350
diff
changeset
|
3604 |
|
10 | 3605 |
/** |
3606 |
* Create a wildcard with the given upper (extends) bound; create |
|
3607 |
* an unbounded wildcard if bound is Object. |
|
3608 |
* |
|
3609 |
* @param bound the upper bound |
|
3610 |
* @param formal the formal type parameter that will be |
|
3611 |
* substituted by the wildcard |
|
3612 |
*/ |
|
3613 |
private WildcardType makeExtendsWildcard(Type bound, TypeVar formal) { |
|
3614 |
if (bound == syms.objectType) { |
|
3615 |
return new WildcardType(syms.objectType, |
|
3616 |
BoundKind.UNBOUND, |
|
3617 |
syms.boundClass, |
|
3618 |
formal); |
|
3619 |
} else { |
|
3620 |
return new WildcardType(bound, |
|
3621 |
BoundKind.EXTENDS, |
|
3622 |
syms.boundClass, |
|
3623 |
formal); |
|
3624 |
} |
|
3625 |
} |
|
3626 |
||
3627 |
/** |
|
3628 |
* Create a wildcard with the given lower (super) bound; create an |
|
3629 |
* unbounded wildcard if bound is bottom (type of {@code null}). |
|
3630 |
* |
|
3631 |
* @param bound the lower bound |
|
3632 |
* @param formal the formal type parameter that will be |
|
3633 |
* substituted by the wildcard |
|
3634 |
*/ |
|
3635 |
private WildcardType makeSuperWildcard(Type bound, TypeVar formal) { |
|
3636 |
if (bound.tag == BOT) { |
|
3637 |
return new WildcardType(syms.objectType, |
|
3638 |
BoundKind.UNBOUND, |
|
3639 |
syms.boundClass, |
|
3640 |
formal); |
|
3641 |
} else { |
|
3642 |
return new WildcardType(bound, |
|
3643 |
BoundKind.SUPER, |
|
3644 |
syms.boundClass, |
|
3645 |
formal); |
|
3646 |
} |
|
3647 |
} |
|
3648 |
||
3649 |
/** |
|
3650 |
* A wrapper for a type that allows use in sets. |
|
3651 |
*/ |
|
3652 |
class SingletonType { |
|
3653 |
final Type t; |
|
3654 |
SingletonType(Type t) { |
|
3655 |
this.t = t; |
|
3656 |
} |
|
3657 |
public int hashCode() { |
|
5004
6c2694dc2da0
6929544: langtools source code uses statics qualified by instance variables
jjg
parents:
3554
diff
changeset
|
3658 |
return Types.hashCode(t); |
10 | 3659 |
} |
3660 |
public boolean equals(Object obj) { |
|
3661 |
return (obj instanceof SingletonType) && |
|
3662 |
isSameType(t, ((SingletonType)obj).t); |
|
3663 |
} |
|
3664 |
public String toString() { |
|
3665 |
return t.toString(); |
|
3666 |
} |
|
3667 |
} |
|
3668 |
// </editor-fold> |
|
3669 |
||
3670 |
// <editor-fold defaultstate="collapsed" desc="Visitors"> |
|
3671 |
/** |
|
3672 |
* A default visitor for types. All visitor methods except |
|
3673 |
* visitType are implemented by delegating to visitType. Concrete |
|
3674 |
* subclasses must provide an implementation of visitType and can |
|
3675 |
* override other methods as needed. |
|
3676 |
* |
|
3677 |
* @param <R> the return type of the operation implemented by this |
|
3678 |
* visitor; use Void if no return type is needed. |
|
3679 |
* @param <S> the type of the second argument (the first being the |
|
3680 |
* type itself) of the operation implemented by this visitor; use |
|
3681 |
* Void if a second argument is not needed. |
|
3682 |
*/ |
|
3683 |
public static abstract class DefaultTypeVisitor<R,S> implements Type.Visitor<R,S> { |
|
3684 |
final public R visit(Type t, S s) { return t.accept(this, s); } |
|
3685 |
public R visitClassType(ClassType t, S s) { return visitType(t, s); } |
|
3686 |
public R visitWildcardType(WildcardType t, S s) { return visitType(t, s); } |
|
3687 |
public R visitArrayType(ArrayType t, S s) { return visitType(t, s); } |
|
3688 |
public R visitMethodType(MethodType t, S s) { return visitType(t, s); } |
|
3689 |
public R visitPackageType(PackageType t, S s) { return visitType(t, s); } |
|
3690 |
public R visitTypeVar(TypeVar t, S s) { return visitType(t, s); } |
|
3691 |
public R visitCapturedType(CapturedType t, S s) { return visitType(t, s); } |
|
3692 |
public R visitForAll(ForAll t, S s) { return visitType(t, s); } |
|
3693 |
public R visitUndetVar(UndetVar t, S s) { return visitType(t, s); } |
|
3694 |
public R visitErrorType(ErrorType t, S s) { return visitType(t, s); } |
|
3695 |
} |
|
3696 |
||
3697 |
/** |
|
1357 | 3698 |
* A default visitor for symbols. All visitor methods except |
3699 |
* visitSymbol are implemented by delegating to visitSymbol. Concrete |
|
3700 |
* subclasses must provide an implementation of visitSymbol and can |
|
3701 |
* override other methods as needed. |
|
3702 |
* |
|
3703 |
* @param <R> the return type of the operation implemented by this |
|
3704 |
* visitor; use Void if no return type is needed. |
|
3705 |
* @param <S> the type of the second argument (the first being the |
|
3706 |
* symbol itself) of the operation implemented by this visitor; use |
|
3707 |
* Void if a second argument is not needed. |
|
3708 |
*/ |
|
3709 |
public static abstract class DefaultSymbolVisitor<R,S> implements Symbol.Visitor<R,S> { |
|
3710 |
final public R visit(Symbol s, S arg) { return s.accept(this, arg); } |
|
3711 |
public R visitClassSymbol(ClassSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3712 |
public R visitMethodSymbol(MethodSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3713 |
public R visitOperatorSymbol(OperatorSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3714 |
public R visitPackageSymbol(PackageSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3715 |
public R visitTypeSymbol(TypeSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3716 |
public R visitVarSymbol(VarSymbol s, S arg) { return visitSymbol(s, arg); } |
|
3717 |
} |
|
3718 |
||
3719 |
/** |
|
10 | 3720 |
* A <em>simple</em> visitor for types. This visitor is simple as |
3721 |
* captured wildcards, for-all types (generic methods), and |
|
3722 |
* undetermined type variables (part of inference) are hidden. |
|
3723 |
* Captured wildcards are hidden by treating them as type |
|
3724 |
* variables and the rest are hidden by visiting their qtypes. |
|
3725 |
* |
|
3726 |
* @param <R> the return type of the operation implemented by this |
|
3727 |
* visitor; use Void if no return type is needed. |
|
3728 |
* @param <S> the type of the second argument (the first being the |
|
3729 |
* type itself) of the operation implemented by this visitor; use |
|
3730 |
* Void if a second argument is not needed. |
|
3731 |
*/ |
|
3732 |
public static abstract class SimpleVisitor<R,S> extends DefaultTypeVisitor<R,S> { |
|
3733 |
@Override |
|
3734 |
public R visitCapturedType(CapturedType t, S s) { |
|
3735 |
return visitTypeVar(t, s); |
|
3736 |
} |
|
3737 |
@Override |
|
3738 |
public R visitForAll(ForAll t, S s) { |
|
3739 |
return visit(t.qtype, s); |
|
3740 |
} |
|
3741 |
@Override |
|
3742 |
public R visitUndetVar(UndetVar t, S s) { |
|
3743 |
return visit(t.qtype, s); |
|
3744 |
} |
|
3745 |
} |
|
3746 |
||
3747 |
/** |
|
3748 |
* A plain relation on types. That is a 2-ary function on the |
|
3749 |
* form Type × Type → Boolean. |
|
3750 |
* <!-- In plain text: Type x Type -> Boolean --> |
|
3751 |
*/ |
|
3752 |
public static abstract class TypeRelation extends SimpleVisitor<Boolean,Type> {} |
|
3753 |
||
3754 |
/** |
|
3755 |
* A convenience visitor for implementing operations that only |
|
3756 |
* require one argument (the type itself), that is, unary |
|
3757 |
* operations. |
|
3758 |
* |
|
3759 |
* @param <R> the return type of the operation implemented by this |
|
3760 |
* visitor; use Void if no return type is needed. |
|
3761 |
*/ |
|
3762 |
public static abstract class UnaryVisitor<R> extends SimpleVisitor<R,Void> { |
|
3763 |
final public R visit(Type t) { return t.accept(this, null); } |
|
3764 |
} |
|
3765 |
||
3766 |
/** |
|
3767 |
* A visitor for implementing a mapping from types to types. The |
|
3768 |
* default behavior of this class is to implement the identity |
|
3769 |
* mapping (mapping a type to itself). This can be overridden in |
|
3770 |
* subclasses. |
|
3771 |
* |
|
3772 |
* @param <S> the type of the second argument (the first being the |
|
3773 |
* type itself) of this mapping; use Void if a second argument is |
|
3774 |
* not needed. |
|
3775 |
*/ |
|
3776 |
public static class MapVisitor<S> extends DefaultTypeVisitor<Type,S> { |
|
3777 |
final public Type visit(Type t) { return t.accept(this, null); } |
|
3778 |
public Type visitType(Type t, S s) { return t; } |
|
3779 |
} |
|
3780 |
// </editor-fold> |
|
6575
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3781 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3782 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3783 |
// <editor-fold defaultstate="collapsed" desc="Annotation support"> |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3784 |
|
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3785 |
public RetentionPolicy getRetention(Attribute.Compound a) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3786 |
RetentionPolicy vis = RetentionPolicy.CLASS; // the default |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3787 |
Attribute.Compound c = a.type.tsym.attribute(syms.retentionType.tsym); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3788 |
if (c != null) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3789 |
Attribute value = c.member(names.value); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3790 |
if (value != null && value instanceof Attribute.Enum) { |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3791 |
Name levelName = ((Attribute.Enum)value).value.name; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3792 |
if (levelName == names.SOURCE) vis = RetentionPolicy.SOURCE; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3793 |
else if (levelName == names.CLASS) vis = RetentionPolicy.CLASS; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3794 |
else if (levelName == names.RUNTIME) vis = RetentionPolicy.RUNTIME; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3795 |
else ;// /* fail soft */ throw new AssertionError(levelName); |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3796 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3797 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3798 |
return vis; |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3799 |
} |
ae1798028008
6960424: new option -Xpkginfo for better control of when package-info.class is generated
jjg
parents:
6353
diff
changeset
|
3800 |
// </editor-fold> |
10 | 3801 |
} |