mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Coercion warning shouldn't assume that IUO is always optional
In situations like `_ = ... as! Bool!` the `to` type could either be represented by an optional (default) or unwrapped. Coercion warnings cannot assume that `to` (even though its IUO) is always represented as an optional type. Resolves: rdar://83072606
This commit is contained in:
@@ -7677,8 +7677,11 @@ bool CoercibleOptionalCheckedCastFailure::diagnoseForcedCastExpr() const {
|
||||
|
||||
bool isBridged = CastKind == CheckedCastKind::BridgingCoercion;
|
||||
if (isCastTypeIUO()) {
|
||||
toType = toType->getOptionalObjectType();
|
||||
extraFromOptionals++;
|
||||
// IUO type could either be optional or unwrapped.
|
||||
if (auto objType = toType->getOptionalObjectType()) {
|
||||
extraFromOptionals++;
|
||||
toType = objType;
|
||||
}
|
||||
}
|
||||
|
||||
std::string extraFromOptionalsStr(extraFromOptionals, '!');
|
||||
@@ -7776,7 +7779,8 @@ bool NoopCheckedCast::diagnoseForcedCastExpr() const {
|
||||
auto diagLoc = expr->getLoc();
|
||||
|
||||
if (isCastTypeIUO()) {
|
||||
toType = toType->getOptionalObjectType();
|
||||
if (auto objType = toType->getOptionalObjectType())
|
||||
toType = objType;
|
||||
}
|
||||
|
||||
if (fromType->isEqual(toType)) {
|
||||
|
||||
Reference in New Issue
Block a user