mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Fix a couple of issues with the fixit for unused if let bindings.
- Fix SR-1112, where the fixit would eat all characters in the RHS expression except for the last one due to improper SourceRange math. - Noticed by inspection, an expression undergoing an implicit conversion (such as a load from an optional `var`) would be judged as requiring parens, when that's really unnecessary.
This commit is contained in:
@@ -1466,9 +1466,7 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
|
||||
if (auto LP = dyn_cast<VarPattern>(OSP->getSubPattern()))
|
||||
if (isa<NamedPattern>(LP->getSubPattern())) {
|
||||
auto initExpr = SC->getCond()[0].getInitializer();
|
||||
auto beforeExprLoc =
|
||||
initExpr->getStartLoc().getAdvancedLocOrInvalid(-1);
|
||||
if (beforeExprLoc.isValid()) {
|
||||
if (initExpr->getStartLoc().isValid()) {
|
||||
unsigned noParens = initExpr->canAppendCallParentheses();
|
||||
|
||||
// If the subexpr is an "as?" cast, we can rewrite it to
|
||||
@@ -1483,8 +1481,9 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
|
||||
diag::pbd_never_used_stmtcond,
|
||||
var->getName());
|
||||
auto introducerLoc = SC->getCond()[0].getIntroducerLoc();
|
||||
diagIF.fixItReplace(SourceRange(introducerLoc, beforeExprLoc),
|
||||
&"("[noParens]);
|
||||
diagIF.fixItReplaceChars(introducerLoc,
|
||||
initExpr->getStartLoc(),
|
||||
&"("[noParens]);
|
||||
|
||||
if (isIsTest) {
|
||||
// If this was an "x as? T" check, rewrite it to "x is T".
|
||||
|
||||
Reference in New Issue
Block a user