Skip to content

Commit 78fba7e

Browse files
committed
Add optional back onto the toType rather than manually adding a '?'
1 parent 9b9e618 commit 78fba7e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,14 +2881,15 @@ static bool addTypeCoerceFixit(InFlightDiagnostic &diag, ConstraintSystem &CS,
28812881
if (Kind != CheckedCastKind::Unresolved) {
28822882
SmallString<32> buffer;
28832883
llvm::raw_svector_ostream OS(buffer);
2884-
toType->print(OS);
28852884
bool canUseAs = Kind == CheckedCastKind::Coercion ||
28862885
Kind == CheckedCastKind::BridgingCoercion;
2886+
if (bothOptional && canUseAs)
2887+
toType = OptionalType::get(toType);
2888+
toType->print(OS);
28872889
diag.fixItInsert(
28882890
Lexer::getLocForEndOfToken(CS.DC->getASTContext().SourceMgr,
28892891
expr->getEndLoc()),
2890-
(llvm::Twine(canUseAs ? " as " : " as! ") + OS.str() +
2891-
llvm::Twine(canUseAs && bothOptional ? "?" : "")).str());
2892+
(llvm::Twine(canUseAs ? " as " : " as! ") + OS.str()).str());
28922893
return true;
28932894
}
28942895
return false;

0 commit comments

Comments
 (0)