Skip to content

Commit e76ae9c

Browse files
committed
[ConstraintSystem] Use missing protocol fix for sequence element mismatches related to protocols
1 parent 17643a3 commit e76ae9c

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ ERROR(cannot_convert_sequence_element_value,none,
452452
"cannot convert sequence element type %0 to expected type %1",
453453
(Type, Type))
454454
ERROR(cannot_convert_sequence_element_protocol,none,
455-
"sequence element type %0 does not conform to expected type %1",
455+
"sequence element type %0 does not conform to expected protocol %1",
456456
(Type, Type))
457457

458458
ERROR(throws_functiontype_mismatch,none,

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,6 +2829,11 @@ bool MissingContextualConformanceFailure::diagnoseAsError() {
28292829
diagnostic = getDiagnosticFor(Context);
28302830
break;
28312831

2832+
case ConstraintLocator::SequenceElementType: {
2833+
diagnostic = diag::cannot_convert_sequence_element_protocol;
2834+
break;
2835+
}
2836+
28322837
default:
28332838
break;
28342839
}

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,11 @@ bool ConstraintSystem::repairFailures(
22282228
}
22292229

22302230
case ConstraintLocator::SequenceElementType: {
2231+
// This is going to be diagnosed as `missing conformance`,
2232+
// so no need to create duplicate fixes.
2233+
if (rhs->isExistentialType())
2234+
break;
2235+
22312236
conversionsOrFixes.push_back(CollectionElementContextualMismatch::create(
22322237
*this, lhs, rhs, getConstraintLocator(locator)));
22332238
break;

test/stmt/foreach.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func patterns(gir: GoodRange<Int>, gtr: GoodTupleIterator) {
6161
for i : Int in gir { sum = sum + i }
6262
for i in gir { sum = sum + i }
6363
for f : Float in gir { sum = sum + f } // expected-error{{cannot convert sequence element type 'Int' to expected type 'Float'}}
64-
for f : ElementProtocol in gir { } // expected-error {{sequence element type 'Int' does not conform to expected type 'ElementProtocol'}}
64+
for f : ElementProtocol in gir { } // expected-error {{sequence element type 'Int' does not conform to expected protocol 'ElementProtocol'}}
6565

6666
for (i, f) : (Int, Float) in gtr { sum = sum + i }
6767

0 commit comments

Comments
 (0)