src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 110
91eea580fbe9
parent 89
b6d5f53b3b29
child 113
eff38cc97183
equal deleted inserted replaced
107:5a9b808557b6 110:91eea580fbe9
190 * @param req The type that was required. 190 * @param req The type that was required.
191 */ 191 */
192 Type typeError(DiagnosticPosition pos, Object problem, Type found, Type req) { 192 Type typeError(DiagnosticPosition pos, Object problem, Type found, Type req) {
193 log.error(pos, "prob.found.req", 193 log.error(pos, "prob.found.req",
194 problem, found, req); 194 problem, found, req);
195 return syms.errType; 195 return types.createErrorType(found);
196 } 196 }
197 197
198 Type typeError(DiagnosticPosition pos, String problem, Type found, Type req, Object explanation) { 198 Type typeError(DiagnosticPosition pos, String problem, Type found, Type req, Object explanation) {
199 log.error(pos, "prob.found.req.1", problem, found, req, explanation); 199 log.error(pos, "prob.found.req.1", problem, found, req, explanation);
200 return syms.errType; 200 return types.createErrorType(found);
201 } 201 }
202 202
203 /** Report an error that wrong type tag was found. 203 /** Report an error that wrong type tag was found.
204 * @param pos Position to be used for error reporting. 204 * @param pos Position to be used for error reporting.
205 * @param required An internationalized string describing the type tag 205 * @param required An internationalized string describing the type tag
206 * required. 206 * required.
207 * @param found The type that was found. 207 * @param found The type that was found.
208 */ 208 */
209 Type typeTagError(DiagnosticPosition pos, Object required, Object found) { 209 Type typeTagError(DiagnosticPosition pos, Object required, Object found) {
210 log.error(pos, "type.found.req", found, required); 210 log.error(pos, "type.found.req", found, required);
211 return syms.errType; 211 return types.createErrorType(found instanceof Type ? (Type)found : syms.errType);
212 } 212 }
213 213
214 /** Report an error that symbol cannot be referenced before super 214 /** Report an error that symbol cannot be referenced before super
215 * has been called. 215 * has been called.
216 * @param pos Position to be used for error reporting. 216 * @param pos Position to be used for error reporting.
346 return found; 346 return found;
347 if (found.tag <= DOUBLE && req.tag <= DOUBLE) 347 if (found.tag <= DOUBLE && req.tag <= DOUBLE)
348 return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req); 348 return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req);
349 if (found.isSuperBound()) { 349 if (found.isSuperBound()) {
350 log.error(pos, "assignment.from.super-bound", found); 350 log.error(pos, "assignment.from.super-bound", found);
351 return syms.errType; 351 return types.createErrorType(found);
352 } 352 }
353 if (req.isExtendsBound()) { 353 if (req.isExtendsBound()) {
354 log.error(pos, "assignment.to.extends-bound", req); 354 log.error(pos, "assignment.to.extends-bound", req);
355 return syms.errType; 355 return types.createErrorType(found);
356 } 356 }
357 return typeError(pos, diags.fragment("incompatible.types"), found, req); 357 return typeError(pos, diags.fragment("incompatible.types"), found, req);
358 } 358 }
359 359
360 /** Instantiate polymorphic type to some prototype, unless 360 /** Instantiate polymorphic type to some prototype, unless
376 if (ex.isAmbiguous) { 376 if (ex.isAmbiguous) {
377 JCDiagnostic d = ex.getDiagnostic(); 377 JCDiagnostic d = ex.getDiagnostic();
378 log.error(pos, 378 log.error(pos,
379 "undetermined.type" + (d!=null ? ".1" : ""), 379 "undetermined.type" + (d!=null ? ".1" : ""),
380 t, d); 380 t, d);
381 return syms.errType; 381 return types.createErrorType(pt);
382 } else { 382 } else {
383 JCDiagnostic d = ex.getDiagnostic(); 383 JCDiagnostic d = ex.getDiagnostic();
384 return typeError(pos, 384 return typeError(pos,
385 diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d), 385 diags.fragment("incompatible.types" + (d!=null ? ".1" : ""), d),
386 t, pt); 386 t, pt);
467 * @param t The type to be checked. 467 * @param t The type to be checked.
468 */ 468 */
469 Type checkNonVoid(DiagnosticPosition pos, Type t) { 469 Type checkNonVoid(DiagnosticPosition pos, Type t) {
470 if (t.tag == VOID) { 470 if (t.tag == VOID) {
471 log.error(pos, "void.not.allowed.here"); 471 log.error(pos, "void.not.allowed.here");
472 return syms.errType; 472 return types.createErrorType(t);
473 } else { 473 } else {
474 return t; 474 return t;
475 } 475 }
476 } 476 }
477 477
519 return typeTagError(pos, 519 return typeTagError(pos,
520 diags.fragment("type.req.class.array"), 520 diags.fragment("type.req.class.array"),
521 t); 521 t);
522 } else if (!types.isReifiable(t)) { 522 } else if (!types.isReifiable(t)) {
523 log.error(pos, "illegal.generic.type.for.instof"); 523 log.error(pos, "illegal.generic.type.for.instof");
524 return syms.errType; 524 return types.createErrorType(t);
525 } else { 525 } else {
526 return t; 526 return t;
527 } 527 }
528 } 528 }
529 529
1540 final TypeVar tv; 1540 final TypeVar tv;
1541 if (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0) 1541 if (t.tag == TYPEVAR && (t.tsym.flags() & UNATTRIBUTED) != 0)
1542 return; 1542 return;
1543 if (seen.contains(t)) { 1543 if (seen.contains(t)) {
1544 tv = (TypeVar)t; 1544 tv = (TypeVar)t;
1545 tv.bound = new ErrorType(); 1545 tv.bound = types.createErrorType(t);
1546 log.error(pos, "cyclic.inheritance", t); 1546 log.error(pos, "cyclic.inheritance", t);
1547 } else if (t.tag == TYPEVAR) { 1547 } else if (t.tag == TYPEVAR) {
1548 tv = (TypeVar)t; 1548 tv = (TypeVar)t;
1549 seen.add(tv); 1549 seen.add(tv);
1550 for (Type b : types.getBounds(tv)) 1550 for (Type b : types.getBounds(tv))
1595 1595
1596 /** Note that we found an inheritance cycle. */ 1596 /** Note that we found an inheritance cycle. */
1597 private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) { 1597 private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
1598 log.error(pos, "cyclic.inheritance", c); 1598 log.error(pos, "cyclic.inheritance", c);
1599 for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail) 1599 for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
1600 l.head = new ErrorType((ClassSymbol)l.head.tsym); 1600 l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
1601 Type st = types.supertype(c.type); 1601 Type st = types.supertype(c.type);
1602 if (st.tag == CLASS) 1602 if (st.tag == CLASS)
1603 ((ClassType)c.type).supertype_field = new ErrorType((ClassSymbol)st.tsym); 1603 ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
1604 c.type = new ErrorType(c); 1604 c.type = types.createErrorType(c, c.type);
1605 c.flags_field |= ACYCLIC; 1605 c.flags_field |= ACYCLIC;
1606 } 1606 }
1607 1607
1608 /** Check that all methods which implement some 1608 /** Check that all methods which implement some
1609 * method conform to the method they implement. 1609 * method conform to the method they implement.

mercurial