Skip to content

Commit 614f72f

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[cs] use simplifyLocatorToAnchor and revert changes to some test diagnostic messages
1 parent 18d4da1 commit 614f72f

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ bool ForceOptional::diagnose(Expr *root, bool asNote) const {
7373
ForceOptional *ForceOptional::create(ConstraintSystem &cs, Type baseType,
7474
Type unwrappedType,
7575
ConstraintLocator *locator) {
76-
return new (cs.getAllocator())
77-
ForceOptional(cs, baseType, unwrappedType, locator);
76+
return new (cs.getAllocator()) ForceOptional(
77+
cs, baseType, unwrappedType,
78+
cs.getConstraintLocator(simplifyLocatorToAnchor(cs, locator)));
7879
}
7980

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

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
23942394
if (forceUnwrapPossible) {
23952395
conversionsOrFixes.push_back(ForceOptional::create(
23962396
*this, objectType1, objectType1->getOptionalObjectType(),
2397-
getConstraintLocator(locator.getAnchor())));
2397+
getConstraintLocator(locator)));
23982398
}
23992399
}
24002400

@@ -2744,7 +2744,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
27442744
subflags);
27452745
if (result == SolutionKind::Solved) {
27462746
auto *fix = ForceOptional::create(*this, type, optionalObjectType,
2747-
getConstraintLocator(locator.getAnchor()));
2747+
getConstraintLocator(locator));
27482748
if (recordFix(fix)) {
27492749
return SolutionKind::Error;
27502750
}
@@ -3042,7 +3042,7 @@ ConstraintSystem::simplifyFunctionComponentConstraint(
30423042
if (unwrapCount > 0) {
30433043
auto *fix = ForceOptional::create(*this, simplifiedCopy,
30443044
simplifiedCopy->getOptionalObjectType(),
3045-
getConstraintLocator(locator.getAnchor()));
3045+
getConstraintLocator(locator));
30463046
while (unwrapCount-- > 0) {
30473047
if (recordFix(fix))
30483048
return SolutionKind::Error;
@@ -4668,7 +4668,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
46684668
// Record any fixes we attempted to get to the correct solution.
46694669
auto *fix = ForceOptional::create(*this, origType2,
46704670
origType2->getOptionalObjectType(),
4671-
getConstraintLocator(locator.getAnchor()));
4671+
getConstraintLocator(locator));
46724672
while (unwrapCount-- > 0) {
46734673
if (recordFix(fix))
46744674
return SolutionKind::Error;
@@ -4693,7 +4693,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
46934693
if (simplified == SolutionKind::Solved) {
46944694
auto *fix = ForceOptional::create(*this, origType2,
46954695
origType2->getOptionalObjectType(),
4696-
getConstraintLocator(locator.getAnchor()));
4696+
getConstraintLocator(locator));
46974697
while (unwrapCount-- > 0) {
46984698
if (recordFix(fix))
46994699
return SolutionKind::Error;

test/Constraints/closures.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ func simplified1069() {
295295
func genericallyNonOptional<T: AnyObject>(_ a: T, _ b: T, _ c: T) { }
296296

297297
func f(_ a: C?, _ b: C?, _ c: C) {
298-
genericallyNonOptional(a, b, c) // expected-error {{value of optional type 'C?' must be unwrapped to a value of type 'C'}}
299-
// expected-note @-1 {{coalesce}}
300-
// expected-note @-2 {{force-unwrap}}
298+
genericallyNonOptional(a, b, c) // expected-error 2{{value of optional type 'C?' must be unwrapped to a value of type 'C'}}
299+
// expected-note @-1 2{{coalesce}}
300+
// expected-note @-2 2{{force-unwrap}}
301301
}
302302
}
303303
}

test/Constraints/fixes.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ struct S1116 {
160160
}
161161

162162
let a1116: [S1116] = []
163-
var s1116 = Set(1...10).subtracting(a1116.map({ $0.s })) // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
164-
// expected-note@-1{{force-unwrap}}
165-
// expected-note@-2{{coalesce}}
163+
var s1116 = Set(1...10).subtracting(a1116.map({ $0.s })) // expected-error {{cannot convert value of type '[Int?]' to expected argument type 'Set<Int>'}}
166164

167165

168166
func moreComplexUnwrapFixes() {
@@ -204,16 +202,22 @@ func moreComplexUnwrapFixes() {
204202
// expected-note@-4{{force-unwrap using '!'}}{{17-17=!}}
205203

206204
takeNon(os?.value) // expected-error{{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
207-
// expected-note@-1{{force-unwrap using '!'}}{{21-21=!}}
205+
// expected-note@-1{{force-unwrap using '!'}}{{13-14=!}}
208206
// expected-note@-2{{coalesce}}
209207
takeNon(os?.optValue) // expected-error{{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
210-
// expected-note@-1{{force-unwrap using '!'}}{{24-24=!}}
208+
// expected-note@-1{{force-unwrap using '!'}}{{11-11=(}} {{23-23=)!}}
211209
// expected-note@-2{{coalesce}}
212210

213211
func sample(a: Int?, b: Int!) {
214212
let aa = a
213+
// expected-note@-1{{short-circuit using 'guard'}}{{5-5=guard }} {{15-15= else \{ return \}}}
214+
// expected-note@-2{{force-unwrap}}
215+
// expected-note@-3{{coalesce}}
215216

216-
let bb = b
217+
let bb = b // expected-note{{value inferred to be type 'Int?' when initialized with an implicitly unwrapped value}}
218+
// expected-note@-1{{short-circuit using 'guard'}}{{5-5=guard }} {{15-15= else \{ return \}}}
219+
// expected-note@-2{{force-unwrap}}
220+
// expected-note@-3{{coalesce}}
217221

218222
let cc = a
219223

@@ -282,4 +286,4 @@ let _: Int = thing?.e?.a() // expected-error {{value of optional type 'Int?' mus
282286
// expected-note@-2{{force-unwrap}}
283287
let _: Int? = thing?.e?.b // expected-error {{value of optional type 'Int??' must be unwrapped to a value of type 'Int?'}}
284288
// expected-note@-1{{coalesce}}
285-
// expected-note@-2{{force-unwrap}}
289+
// expected-note@-2{{force-unwrap}}

0 commit comments

Comments
 (0)