[Diagnostics] Substring -> String fix-it should be anchored at semantic expressoin

If contextual failure is detected in sub-expression (through
type-check call via CSDiag), let's make sure that fix-it
is always anchored at semantic expression otherwise it could be
attached to the paren representing whole argument list.
This commit is contained in:
Pavel Yaskevich
2019-08-08 09:43:57 -07:00
parent fd85bfe045
commit 290ec3c1cc

View File

@@ -2210,7 +2210,8 @@ bool ContextualFailure::trySequenceSubsequenceFixIts(
// Wrap in String.init
if (FromType->isEqual(Substring)) {
if (ToType->isEqual(String)) {
auto range = getAnchor()->getSourceRange();
auto *anchor = getAnchor()->getSemanticsProvidingExpr();
auto range = anchor->getSourceRange();
diagnostic.fixItInsert(range.Start, "String(");
diagnostic.fixItInsertAfter(range.End, ")");
return true;