Skip to content

Commit 5218c2c

Browse files
authored
[Sema] Add note to all unresolved witness types instead of just the first one. (#3458)
When issuing the error of "not conforming to a protocol P", we used to only note the first unresolved witness type. This is inconsistent with the situation when the conformance fails due to unimplemented functions, which we note all of the unimplemented functions. This patch fixed this by noting all unresolved witness types.
1 parent 8f5742c commit 5218c2c

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,16 +3413,14 @@ void ConformanceChecker::resolveTypeWitnesses() {
34133413
return;
34143414
}
34153415

3416-
// Complain that we couldn't find anything.
3417-
if (!missingTypeWitness)
3418-
missingTypeWitness = *unresolvedAssocTypes.begin();
3419-
3420-
diagnoseOrDefer(missingTypeWitness, true,
3421-
[missingTypeWitness](TypeChecker &tc,
3422-
NormalProtocolConformance *conformance) {
3423-
tc.diagnose(missingTypeWitness, diag::no_witnesses_type,
3424-
missingTypeWitness->getName());
3425-
});
3416+
for (auto missingTypeWitness : unresolvedAssocTypes) {
3417+
diagnoseOrDefer(missingTypeWitness, true,
3418+
[missingTypeWitness](TypeChecker &tc,
3419+
NormalProtocolConformance *conformance) {
3420+
tc.diagnose(missingTypeWitness, diag::no_witnesses_type,
3421+
missingTypeWitness->getName());
3422+
});
3423+
}
34263424

34273425
return;
34283426
}

test/decl/ext/protocol.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,11 @@ class BadClass1 : BadProto1 {
899899
func foo() { }
900900
override var prop: Int { return 5 } // expected-error{{property does not override any property from its superclass}}
901901
}
902+
903+
protocol BadProto5 {
904+
associatedtype T1 // expected-note{{protocol requires nested type 'T1'}}
905+
associatedtype T2 // expected-note{{protocol requires nested type 'T2'}}
906+
associatedtype T3 // expected-note{{protocol requires nested type 'T3'}}
907+
}
908+
909+
class BadClass5 : BadProto5 {} // expected-error{{type 'BadClass5' does not conform to protocol 'BadProto5'}}

0 commit comments

Comments
 (0)