420 * @param pos Position to be used for error reporting. |
420 * @param pos Position to be used for error reporting. |
421 * @param a The type that should be bounded by bs. |
421 * @param a The type that should be bounded by bs. |
422 * @param bs The bound. |
422 * @param bs The bound. |
423 */ |
423 */ |
424 private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { |
424 private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) { |
425 if (!(a instanceof CapturedType)) { |
425 if (a.tag == TYPEVAR && ((TypeVar)a).isCaptured()) { |
|
426 CapturedType ct = (CapturedType)a; |
|
427 boolean ok; |
|
428 if (ct.bound.isErroneous()) {//capture doesn't exist |
|
429 ok = false; |
|
430 } |
|
431 else { |
|
432 switch (ct.wildcard.kind) { |
|
433 case EXTENDS: |
|
434 ok = types.isCastable(bs.getUpperBound(), |
|
435 types.upperBound(a), |
|
436 Warner.noWarnings); |
|
437 break; |
|
438 case SUPER: |
|
439 ok = !types.notSoftSubtype(types.lowerBound(a), |
|
440 bs.getUpperBound()); |
|
441 break; |
|
442 case UNBOUND: |
|
443 ok = true; |
|
444 break; |
|
445 default: |
|
446 throw new AssertionError("Invalid bound kind"); |
|
447 } |
|
448 } |
|
449 if (!ok) |
|
450 log.error(pos, "not.within.bounds", a); |
|
451 } |
|
452 else { |
426 a = types.upperBound(a); |
453 a = types.upperBound(a); |
427 for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { |
454 for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) { |
428 if (!types.isSubtype(a, l.head)) { |
455 if (!types.isSubtype(a, l.head)) { |
429 log.error(pos, "not.within.bounds", a); |
456 log.error(pos, "not.within.bounds", a); |
430 return; |
457 return; |
431 } |
458 } |
432 } |
459 } |
433 } |
|
434 else { |
|
435 CapturedType ct = (CapturedType)a; |
|
436 boolean ok = false; |
|
437 switch (ct.wildcard.kind) { |
|
438 case EXTENDS: |
|
439 ok = types.isCastable(bs.getUpperBound(), |
|
440 types.upperBound(a), |
|
441 Warner.noWarnings); |
|
442 break; |
|
443 case SUPER: |
|
444 ok = !types.notSoftSubtype(types.lowerBound(a), |
|
445 bs.getUpperBound()); |
|
446 break; |
|
447 case UNBOUND: |
|
448 ok = true; |
|
449 } |
|
450 if (!ok) |
|
451 log.error(pos, "not.within.bounds", a); |
|
452 } |
460 } |
453 } |
461 } |
454 |
462 |
455 /** Check that type is different from 'void'. |
463 /** Check that type is different from 'void'. |
456 * @param pos Position to be used for error reporting. |
464 * @param pos Position to be used for error reporting. |