Skip to content

Commit 99acf81

Browse files
committed
[Diag] Correct fixit location of "?" when pattern matching optional with non-optional
Trying to pattern match an optional with a non-optional should provide a fixit inserting a "?" after the last token and not before it.
1 parent 882d8c4 commit 99acf81

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6124,7 +6124,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
61246124
diag.highlight(rhsExpr->getSourceRange());
61256125
if (auto optUnwrappedType = rhsType->getOptionalObjectType()) {
61266126
if (lhsType->isEqual(optUnwrappedType)) {
6127-
diag.fixItInsert(lhsExpr->getEndLoc(), "?");
6127+
diag.fixItInsertAfter(lhsExpr->getEndLoc(), "?");
61286128
}
61296129
}
61306130
return true;

test/Constraints/patterns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ default: break
165165

166166
// <rdar://problem/21995744> QoI: Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'
167167
switch ("foo" as String?) {
168-
case "what": break // expected-error{{expression pattern of type 'String' cannot match values of type 'String?'}}
168+
case "what": break // expected-error{{expression pattern of type 'String' cannot match values of type 'String?'}} {{12-12=?}}
169169
default: break
170170
}
171171

test/expr/unary/selector/selector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ default:
134134
}
135135

136136
switch optionalSel {
137-
case #selector(SR1827.bar): // expected-error{{expression pattern of type 'Selector' cannot match values of type 'Selector?'}} {{26-26=?}}
137+
case #selector(SR1827.bar): // expected-error{{expression pattern of type 'Selector' cannot match values of type 'Selector?'}} {{27-27=?}}
138138
break
139139
case #selector(SR1827.bar)!: // expected-error{{cannot force unwrap value of non-optional type 'Selector'}}
140140
break

0 commit comments

Comments
 (0)