File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -597,7 +597,10 @@ bool Expr::canAppendCallParentheses() const {
597
597
case ExprKind::PointerToPointer:
598
598
case ExprKind::LValueToPointer:
599
599
case ExprKind::ForeignObjectConversion:
600
- return false ;
600
+ // Implicit conversion nodes have no syntax of their own; defer to the
601
+ // subexpression.
602
+ return cast<ImplicitConversionExpr>(this )->getSubExpr ()
603
+ ->canAppendCallParentheses ();
601
604
602
605
case ExprKind::ForcedCheckedCast:
603
606
case ExprKind::ConditionalCheckedCast:
Original file line number Diff line number Diff line change @@ -1460,9 +1460,7 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
1460
1460
if (auto LP = dyn_cast<VarPattern>(OSP->getSubPattern ()))
1461
1461
if (isa<NamedPattern>(LP->getSubPattern ())) {
1462
1462
auto initExpr = SC->getCond ()[0 ].getInitializer ();
1463
- auto beforeExprLoc =
1464
- initExpr->getStartLoc ().getAdvancedLocOrInvalid (-1 );
1465
- if (beforeExprLoc.isValid ()) {
1463
+ if (initExpr->getStartLoc ().isValid ()) {
1466
1464
unsigned noParens = initExpr->canAppendCallParentheses ();
1467
1465
1468
1466
// If the subexpr is an "as?" cast, we can rewrite it to
@@ -1477,8 +1475,9 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
1477
1475
diag::pbd_never_used_stmtcond,
1478
1476
var->getName ());
1479
1477
auto introducerLoc = SC->getCond ()[0 ].getIntroducerLoc ();
1480
- diagIF.fixItReplace (SourceRange (introducerLoc, beforeExprLoc),
1481
- &" (" [noParens]);
1478
+ diagIF.fixItReplaceChars (introducerLoc,
1479
+ initExpr->getStartLoc (),
1480
+ &" (" [noParens]);
1482
1481
1483
1482
if (isIsTest) {
1484
1483
// If this was an "x as? T" check, rewrite it to "x is T".
Original file line number Diff line number Diff line change @@ -197,7 +197,6 @@ func testFixitsInStatementsWithPatterns(a : Int?) {
197
197
}
198
198
}
199
199
200
-
201
200
// <rdar://22774938> QoI: "never used" in an "if let" should rewrite expression to use != nil
202
201
func test( a : Int ? , b : Any ) {
203
202
if true == true , let x = a { // expected-warning {{immutable value 'x' was never used; consider replacing with '_' or removing it}} {{24-25=_}}
@@ -217,7 +216,19 @@ func test(a : Int?, b : Any) {
217
216
if let x = b as? Int { // expected-warning {{value 'x' was defined but never used; consider replacing with boolean test}} {{6-14=}} {{16-19=is}}
218
217
}
219
218
220
-
219
+ // SR-1112
220
+
221
+ let xxx: Int? = 0
222
+
223
+ if let yyy = xxx { } // expected-warning{{with boolean test}} {{6-16=}} {{19-19= != nil}}
224
+
225
+ var zzz: Int? = 0
226
+ zzz = 1
227
+
228
+ if let yyy = zzz { } // expected-warning{{with boolean test}} {{6-16=}} {{19-19= != nil}}
229
+
230
+ if let yyy = zzz ?? xxx { } // expected-warning{{with boolean test}} {{6-16=(}} {{26-26=) != nil}}
231
+
221
232
}
222
233
223
234
You can’t perform that action at this time.
0 commit comments