Skip to content

Commit fb6503f

Browse files
Merge pull request #41830 from LucianoPAlmeida/SR-15970-optional-conformance
[Diagnostic][Sema] Drop OptionalPayload locator element in contextual conformance failure diagnostics
2 parents 3aa4c0e + 1505d7c commit fb6503f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
34073407

34083408
if (last.is<LocatorPathElt::ApplyArgToParam>()) {
34093409
auto *fix = AllowArgumentMismatch::create(
3410-
*this, type1, proto, getConstraintLocator(locator));
3410+
*this, type1, proto, getConstraintLocator(anchor, path));
34113411

34123412
// Impact is 2 here because there are two failures
34133413
// 1 - missing conformance and 2 - incorrect argument type.
@@ -3443,14 +3443,14 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
34433443

34443444
if (isExpr<CoerceExpr>(anchor)) {
34453445
auto *fix = ContextualMismatch::create(
3446-
*this, type1, type2, getConstraintLocator(locator));
3446+
*this, type1, type2, getConstraintLocator(anchor, path));
34473447
if (recordFix(fix))
34483448
return getTypeMatchFailure(locator);
34493449
break;
34503450
}
34513451

34523452
auto *fix = MissingConformance::forContextual(
3453-
*this, type1, proto, getConstraintLocator(locator));
3453+
*this, type1, proto, getConstraintLocator(anchor, path));
34543454

34553455
if (recordFix(fix))
34563456
return getTypeMatchFailure(locator);

test/Constraints/protocols.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,15 @@ case test(cond: Bool, v: Int64)
519519
}
520520
}
521521
}
522+
523+
// SR-15970
524+
protocol SR15970_P {}
525+
struct SR15970_S {}
526+
527+
func SR15970_F(x: Int) -> SR15970_P {
528+
return SR15970_S() // expected-error{{return expression of type 'SR15970_S' does not conform to 'SR15970_P'}}
529+
}
530+
531+
func SR15970_F1(x: Int) -> SR15970_P? {
532+
return SR15970_S() // expected-error{{return expression of type 'SR15970_S' does not conform to 'SR15970_P'}}
533+
}

0 commit comments

Comments
 (0)