1416 } else { |
1416 } else { |
1417 return false; |
1417 return false; |
1418 } |
1418 } |
1419 } |
1419 } |
1420 |
1420 |
1421 if (t.isCompound()) { |
1421 if (t.isCompound() || s.isCompound()) { |
1422 Warner oldWarner = warnStack.head; |
1422 return !t.isCompound() ? |
1423 warnStack.head = noWarnings; |
1423 visitIntersectionType((IntersectionClassType)s, t, true) : |
1424 if (!visit(supertype(t), s)) |
1424 visitIntersectionType((IntersectionClassType)t, s, false); |
1425 return false; |
|
1426 for (Type intf : interfaces(t)) { |
|
1427 if (!visit(intf, s)) |
|
1428 return false; |
|
1429 } |
|
1430 if (warnStack.head.hasLint(LintCategory.UNCHECKED)) |
|
1431 oldWarner.warn(LintCategory.UNCHECKED); |
|
1432 return true; |
|
1433 } |
|
1434 |
|
1435 if (s.isCompound()) { |
|
1436 // call recursively to reuse the above code |
|
1437 return visitClassType((ClassType)s, t); |
|
1438 } |
1425 } |
1439 |
1426 |
1440 if (s.tag == CLASS || s.tag == ARRAY) { |
1427 if (s.tag == CLASS || s.tag == ARRAY) { |
1441 boolean upcast; |
1428 boolean upcast; |
1442 if ((upcast = isSubtype(erasure(t), erasure(s))) |
1429 if ((upcast = isSubtype(erasure(t), erasure(s))) |
1510 } |
1497 } |
1511 } |
1498 } |
1512 return false; |
1499 return false; |
1513 } |
1500 } |
1514 |
1501 |
|
1502 boolean visitIntersectionType(IntersectionClassType ict, Type s, boolean reverse) { |
|
1503 Warner warn = noWarnings; |
|
1504 for (Type c : ict.getComponents()) { |
|
1505 warn.clear(); |
|
1506 if (reverse ? !isCastable(s, c, warn) : !isCastable(c, s, warn)) |
|
1507 return false; |
|
1508 } |
|
1509 if (warn.hasLint(LintCategory.UNCHECKED)) |
|
1510 warnStack.head.warn(LintCategory.UNCHECKED); |
|
1511 return true; |
|
1512 } |
|
1513 |
1515 @Override |
1514 @Override |
1516 public Boolean visitArrayType(ArrayType t, Type s) { |
1515 public Boolean visitArrayType(ArrayType t, Type s) { |
1517 switch (s.tag) { |
1516 switch (s.tag) { |
1518 case ERROR: |
1517 case ERROR: |
1519 case BOT: |
1518 case BOT: |
3887 warn.warn(LintCategory.UNCHECKED); |
3886 warn.warn(LintCategory.UNCHECKED); |
3888 return true; |
3887 return true; |
3889 } |
3888 } |
3890 |
3889 |
3891 private boolean giveWarning(Type from, Type to) { |
3890 private boolean giveWarning(Type from, Type to) { |
3892 Type subFrom = asSub(from, to.tsym); |
3891 List<Type> bounds = to.isCompound() ? |
3893 return to.isParameterized() && |
3892 ((IntersectionClassType)to).getComponents() : List.of(to); |
3894 (!(isUnbounded(to) || |
3893 for (Type b : bounds) { |
3895 isSubtype(from, to) || |
3894 Type subFrom = asSub(from, b.tsym); |
3896 ((subFrom != null) && containsType(to.allparams(), subFrom.allparams())))); |
3895 if (b.isParameterized() && |
|
3896 (!(isUnbounded(b) || |
|
3897 isSubtype(from, b) || |
|
3898 ((subFrom != null) && containsType(b.allparams(), subFrom.allparams()))))) { |
|
3899 return true; |
|
3900 } |
|
3901 } |
|
3902 return false; |
3897 } |
3903 } |
3898 |
3904 |
3899 private List<Type> superClosure(Type t, Type s) { |
3905 private List<Type> superClosure(Type t, Type s) { |
3900 List<Type> cl = List.nil(); |
3906 List<Type> cl = List.nil(); |
3901 for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |
3907 for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { |