Skip to content

Commit e7da527

Browse files
authored
Merge pull request swiftlang#10152 from ahoppen/fixit-optional-switch
[Diag] Correct fixit location of "?" when pattern matching optional with non-optional
2 parents 92a8668 + 99acf81 commit e7da527

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
@@ -6240,7 +6240,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
62406240
diag.highlight(rhsExpr->getSourceRange());
62416241
if (auto optUnwrappedType = rhsType->getOptionalObjectType()) {
62426242
if (lhsType->isEqual(optUnwrappedType)) {
6243-
diag.fixItInsert(lhsExpr->getEndLoc(), "?");
6243+
diag.fixItInsertAfter(lhsExpr->getEndLoc(), "?");
62446244
}
62456245
}
62466246
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)