Emit a different diagnostic for Swift 3/4 for 'as T!'.

We ended up supporting these coercions for Swift 3/4 via disjunctions,
so change our warning to one saying that it's deprecated rather than
erroneously telling the user that we're treating '!' as if it
were '?'.

Fixes rdar://problem/37121121.
This commit is contained in:
Mark Lacey
2018-03-29 23:40:45 -07:00
parent fcd86e3246
commit f47218cb86
5 changed files with 36 additions and 14 deletions

View File

@@ -2525,6 +2525,9 @@ namespace {
// Validate the resulting type.
TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
options |= TypeResolutionFlags::InExpression;
// Prior to Swift 5, we allow 'as T!' and turn it into a disjunction.
if (!CS.getASTContext().isSwiftVersionAtLeast(5))
options |= TypeResolutionFlags::AllowIUODeprecated;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
@@ -2554,6 +2557,9 @@ namespace {
// Validate the resulting type.
TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
options |= TypeResolutionFlags::InExpression;
// Prior to Swift 5, we allow 'as T!' and turn it into a disjunction.
if (!CS.getASTContext().isSwiftVersionAtLeast(5))
options |= TypeResolutionFlags::AllowIUODeprecated;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;
@@ -2588,6 +2594,9 @@ namespace {
// Validate the resulting type.
TypeResolutionOptions options = TypeResolutionFlags::AllowUnboundGenerics;
options |= TypeResolutionFlags::InExpression;
// Prior to Swift 5, we allow 'as T!' and turn it into a disjunction.
if (!CS.getASTContext().isSwiftVersionAtLeast(5))
options |= TypeResolutionFlags::AllowIUODeprecated;
if (tc.validateType(expr->getCastTypeLoc(), CS.DC, options))
return nullptr;