Skip to content

Commit acbf495

Browse files
committed
Store full locator info on ForceOptional
For the purposes of fix deduplication, we want to use the simplified locator. However for the purposes of diagnostics, preserve the full locator, which gives us more information to work with.
1 parent 179c81d commit acbf495

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/Sema/CSFix.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,17 @@ ForceDowncast *ForceDowncast::create(ConstraintSystem &cs, Type toType,
6767

6868
bool ForceOptional::diagnose(Expr *root, bool asNote) const {
6969
MissingOptionalUnwrapFailure failure(root, getConstraintSystem(), BaseType,
70-
UnwrappedType, getLocator());
70+
UnwrappedType, FullLocator);
7171
return failure.diagnose(asNote);
7272
}
7373

7474
ForceOptional *ForceOptional::create(ConstraintSystem &cs, Type baseType,
7575
Type unwrappedType,
7676
ConstraintLocator *locator) {
77-
return new (cs.getAllocator()) ForceOptional(
78-
cs, baseType, unwrappedType,
79-
cs.getConstraintLocator(simplifyLocatorToAnchor(cs, locator)));
77+
auto *simplifiedLocator =
78+
cs.getConstraintLocator(simplifyLocatorToAnchor(cs, locator));
79+
return new (cs.getAllocator())
80+
ForceOptional(cs, baseType, unwrappedType, simplifiedLocator, locator);
8081
}
8182

8283
bool UnwrapOptionalBase::diagnose(Expr *root, bool asNote) const {

lib/Sema/CSFix.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,14 @@ class ForceDowncast final : public ConstraintFix {
231231
class ForceOptional final : public ConstraintFix {
232232
Type BaseType;
233233
Type UnwrappedType;
234+
ConstraintLocator *FullLocator;
234235

235236
ForceOptional(ConstraintSystem &cs, Type baseType, Type unwrappedType,
236-
ConstraintLocator *locator)
237-
: ConstraintFix(cs, FixKind::ForceOptional, locator), BaseType(baseType),
238-
UnwrappedType(unwrappedType) {
237+
ConstraintLocator *simplifiedLocator,
238+
ConstraintLocator *fullLocator)
239+
: ConstraintFix(cs, FixKind::ForceOptional, simplifiedLocator),
240+
BaseType(baseType), UnwrappedType(unwrappedType),
241+
FullLocator(fullLocator) {
239242
assert(baseType && "Base type must not be null");
240243
assert(unwrappedType && "Unwrapped type must not be null");
241244
}

0 commit comments

Comments
 (0)