Skip to content

Commit 525b6ef

Browse files
committed
Sema: Use diagnoseOrDefer() in ConformanceChecker::ensureRequirementsAreSatisfied()
1 parent 2973e3f commit 525b6ef

7 files changed

+19
-27
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,20 +5110,19 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
51105110
// Diagnose the failure generically.
51115111
// FIXME: Would be nice to give some more context here!
51125112
if (!Conformance->isInvalid()) {
5113-
diags.diagnose(Loc, diag::type_does_not_conform,
5114-
Adoptee,
5115-
Proto->getDeclaredInterfaceType());
5116-
51175113
if (result.getKind() == CheckRequirementsResult::RequirementFailure) {
5118-
TypeChecker::diagnoseRequirementFailure(
5119-
result.getRequirementFailureInfo(), Loc, Loc,
5120-
proto->getDeclaredInterfaceType(),
5121-
{proto->getSelfInterfaceType()->castTo<GenericTypeParamType>()},
5122-
QuerySubstitutionMap{substitutions}, module);
5114+
auto Loc = this->Loc;
5115+
diagnoseOrDefer(nullptr, /*isError=*/true,
5116+
[Loc, result, proto, substitutions, module](NormalProtocolConformance *conformance) {
5117+
TypeChecker::diagnoseRequirementFailure(
5118+
result.getRequirementFailureInfo(), Loc, Loc,
5119+
proto->getDeclaredInterfaceType(),
5120+
{proto->getSelfInterfaceType()->castTo<GenericTypeParamType>()},
5121+
QuerySubstitutionMap{substitutions}, module);
5122+
});
51235123
}
51245124

51255125
Conformance->setInvalid();
5126-
AlreadyComplained = true;
51275126
}
51285127
return;
51295128
}

test/Distributed/distributed_actor_system_missing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Distributed
88

99
distributed actor DA {
10-
// expected-error@-1{{distributed actor 'DA' does not declare ActorSystem it can be used with.}}
10+
// expected-error@-1{{distributed actor 'DA' does not declare ActorSystem it can be used with}}
1111

1212
// Since synthesis would have failed due to the missing ActorSystem:
1313
// expected-error@-4{{type 'DA' does not conform to protocol 'Encodable'}}
@@ -23,7 +23,7 @@ distributed actor DA {
2323
// we need to fail gracefully, rather than crash trying to use the non-existing type.
2424
//
2525
// Test case for: https://github.com/apple/swift/issues/58663
26-
distributed actor Server { // expected-error 2 {{distributed actor 'Server' does not declare ActorSystem it can be used with.}}
26+
distributed actor Server { // expected-error 2 {{distributed actor 'Server' does not declare ActorSystem it can be used with}}
2727
// expected-note@-1{{you can provide a module-wide default actor system by declaring:}}
2828
typealias ActorSystem = DoesNotExistDataSystem
2929
// expected-error@-1{{cannot find type 'DoesNotExistDataSystem' in scope}}

test/Distributed/distributed_actor_system_missing_type_dontCrash.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Distributed
88

99
// rdar://90886302 This test would crash if not typealias ActorSystem was declared for an actor
1010
distributed actor Fish {
11-
// expected-error@-1{{distributed actor 'Fish' does not declare ActorSystem it can be used with.}}
12-
// expected-error@-2{{distributed actor 'Fish' does not declare ActorSystem it can be used with.}}
11+
// expected-error@-1{{distributed actor 'Fish' does not declare ActorSystem it can be used with}}
12+
// expected-error@-2{{distributed actor 'Fish' does not declare ActorSystem it can be used with}}
1313
// expected-note@-3{{you can provide a module-wide default actor system by declaring:\ntypealias DefaultDistributedActorSystem = <#ConcreteActorSystem#>}}
1414

1515
distributed func tell(_ text: String, by: Fish) {

test/Distributed/distributed_protocols_distributed_func_serialization_requirements.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ protocol ProtocolWithChecksSeqReq: DistributedActor
4747
distributed func testAT() async throws -> NotCodable
4848
}
4949
distributed actor ProtocolWithChecksSeqReqDA_MissingSystem: ProtocolWithChecksSeqReq {
50-
// expected-error@-1{{distributed actor 'ProtocolWithChecksSeqReqDA_MissingSystem' does not declare ActorSystem it can be used with.}}
50+
// expected-error@-1{{distributed actor 'ProtocolWithChecksSeqReqDA_MissingSystem' does not declare ActorSystem it can be used with}}
5151
// expected-note@-2{{you can provide a module-wide default actor system by declaring:}}
52-
// expected-error@-3{{type 'ProtocolWithChecksSeqReqDA_MissingSystem' does not conform to protocol 'ProtocolWithChecksSeqReq'}}
5352
//
54-
// expected-error@-5{{distributed actor 'ProtocolWithChecksSeqReqDA_MissingSystem' does not declare ActorSystem it can be used with.}}
53+
// expected-error@-4{{distributed actor 'ProtocolWithChecksSeqReqDA_MissingSystem' does not declare ActorSystem it can be used with}}
5554

5655
// Entire conformance is doomed, so we didn't proceed to checking the functions; that's fine
5756
distributed func testAT() async throws -> NotCodable { .init() }

test/decl/protocol/req/associated_type_inference.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,7 @@ protocol P35a {
572572
associatedtype B // expected-note {{protocol requires nested type 'B'}}
573573
}
574574
protocol P35b: P35a where B == A {}
575-
// expected-error@+2 {{type 'S35' does not conform to protocol 'P35a'}}
576-
// expected-error@+1 {{type 'S35' does not conform to protocol 'P35b'}}
575+
// expected-error@+1 {{type 'S35' does not conform to protocol 'P35a'}}
577576
struct S35: P35b {}
578577

579578
// Circular reference through a value witness.
@@ -634,7 +633,6 @@ protocol P40b: P40a {
634633
protocol P40c: P40b where D == S40<Never> {}
635634
struct S40<E: Equatable>: P40c {
636635
// expected-error@-1 {{type 'S40<E>' does not conform to protocol 'P40b'}}
637-
// expected-error@-2 {{type 'S40<E>' does not conform to protocol 'P40c'}}
638636
func foo(arg: Never) {}
639637

640638
typealias B = Self
@@ -712,6 +710,5 @@ protocol FIXME_P1a {
712710
associatedtype B: FIXME_P1a // expected-note {{protocol requires nested type 'B'}}
713711
}
714712
protocol FIXME_P1b: FIXME_P1a where B == FIXME_S1<A> {}
715-
// expected-error@+2 {{type 'FIXME_S1<T>' does not conform to protocol 'FIXME_P1a'}}
716-
// expected-error@+1 {{type 'FIXME_S1<T>' does not conform to protocol 'FIXME_P1b'}}
713+
// expected-error@+1 {{type 'FIXME_S1<T>' does not conform to protocol 'FIXME_P1a'}}
717714
struct FIXME_S1<T: Equatable>: FIXME_P1b {}

test/decl/protocol/req/associated_type_inference_fixed_type.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ protocol Q11 {
108108
}
109109
do {
110110
struct Conformer: Q11, P11b {}
111-
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P11b'}}
112-
// expected-error@-2 {{type 'Conformer' does not conform to protocol 'P11a'}}
113-
// expected-error@-3 {{type 'Conformer' does not conform to protocol 'Q11'}}
111+
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P11a'}}
112+
// expected-error@-2 {{type 'Conformer' does not conform to protocol 'Q11'}}
114113
}
115114

116115
protocol P12 where A == B {
@@ -151,7 +150,6 @@ protocol P15b: P15a where A == B {}
151150
do {
152151
struct Conformer: P15b {}
153152
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P15a'}}
154-
// expected-error@-2 {{type 'Conformer' does not conform to protocol 'P15b'}}
155153
}
156154

157155
protocol P16a where A == B {

test/decl/protocol/req/associated_type_inference_fixed_type_experimental_inference.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,5 +885,4 @@ do {
885885
struct Conformer: P48c {}
886886
// expected-error@-1 {{type 'Conformer' does not conform to protocol 'P48a'}}
887887
// expected-error@-2 {{type 'Conformer' does not conform to protocol 'P48b'}}
888-
// expected-error@-3 {{type 'Conformer' does not conform to protocol 'P48c'}}
889888
}

0 commit comments

Comments
 (0)