Speculatively fix optionals by unwrapping them with '!'.

Example:

test/Constraints/fixes.swift:54:9: error: value of optional type 'B?'
    not unwrapped; did you mean to use '!' or '?'?
  b = a as B
        ^
            !

Swift SVN r16938
This commit is contained in:
Doug Gregor
2014-04-27 20:41:02 +00:00
parent 321911a059
commit eaf2bf632f
5 changed files with 48 additions and 2 deletions

View File

@@ -3853,6 +3853,23 @@ Expr *ConstraintSystem::applySolution(const Solution &solution,
diagnosed = true;
break;
}
case ExprFixKind::ForceOptional:
case ExprFixKind::ForceDowncast: {
auto type = solution.simplifyType(TC, affected->getType())
->getRValueType();
SourceLoc afterAffectedLoc
= Lexer::getLocForEndOfToken(TC.Context.SourceMgr,
affected->getEndLoc());
TC.diagnose(affected->getLoc(),
fix.first == ExprFixKind::ForceOptional
? diag::missing_unwrap_optional
: diag::missing_forced_downcast,
type)
.fixItInsert(afterAffectedLoc, "!");
diagnosed = true;
break;
}
}
}