@@ -6056,72 +6056,98 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
6056
6056
}
6057
6057
6058
6058
auto proto = conformance->getProtocol ();
6059
- if (proto->isSpecificProtocol (
6060
- KnownProtocolKind::StringInterpolationProtocol)) {
6061
- if (auto typeDecl = dc->getSelfNominalTypeDecl ()) {
6062
- diagnoseMissingAppendInterpolationMethod (typeDecl);
6059
+
6060
+ if (auto kp = proto->getKnownProtocolKind ()) {
6061
+ switch (*kp) {
6062
+ case KnownProtocolKind::StringInterpolationProtocol: {
6063
+ if (auto typeDecl = dc->getSelfNominalTypeDecl ()) {
6064
+ diagnoseMissingAppendInterpolationMethod (typeDecl);
6065
+ }
6066
+ break ;
6063
6067
}
6064
- } else if (proto-> isSpecificProtocol ( KnownProtocolKind::Sendable)) {
6065
- SendableConformance = conformance;
6068
+ case KnownProtocolKind::Sendable: {
6069
+ SendableConformance = conformance;
6066
6070
6067
- if (auto normal = conformance->getRootNormalConformance ()) {
6068
- if (isImpliedByConformancePredatingConcurrency (normal ))
6069
- sendableConformancePreconcurrency = true ;
6071
+ if (auto normal = conformance->getRootNormalConformance ()) {
6072
+ if (isImpliedByConformancePredatingConcurrency (normal ))
6073
+ sendableConformancePreconcurrency = true ;
6074
+ }
6075
+ break ;
6070
6076
}
6071
- } else if (proto->isSpecificProtocol (KnownProtocolKind::DistributedActor)) {
6072
- if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6073
- if (!classDecl->isDistributedActor ()) {
6074
- if (classDecl->isActor ()) {
6075
- dc->getSelfNominalTypeDecl ()
6076
- ->diagnose (diag::actor_cannot_inherit_distributed_actor_protocol,
6077
- dc->getSelfNominalTypeDecl ()->getName ())
6078
- .fixItInsert (classDecl->getStartLoc (), " distributed " );
6079
- } else {
6077
+ case KnownProtocolKind::DistributedActor: {
6078
+ if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6079
+ if (!classDecl->isDistributedActor ()) {
6080
+ if (classDecl->isActor ()) {
6081
+ dc->getSelfNominalTypeDecl ()
6082
+ ->diagnose (diag::actor_cannot_inherit_distributed_actor_protocol,
6083
+ dc->getSelfNominalTypeDecl ()->getName ())
6084
+ .fixItInsert (classDecl->getStartLoc (), " distributed " );
6085
+ } else {
6086
+ dc->getSelfNominalTypeDecl ()
6087
+ ->diagnose (diag::distributed_actor_protocol_illegal_inheritance,
6088
+ dc->getSelfNominalTypeDecl ()->getName ())
6089
+ .fixItReplace (nominal->getStartLoc (), " distributed actor" );
6090
+ }
6091
+ }
6092
+ }
6093
+ break ;
6094
+ }
6095
+ case KnownProtocolKind::DistributedActorSystem: {
6096
+ checkDistributedActorSystem (nominal);
6097
+ break ;
6098
+ }
6099
+ case KnownProtocolKind::Actor: {
6100
+ if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6101
+ if (!classDecl->isExplicitActor ()) {
6080
6102
dc->getSelfNominalTypeDecl ()
6081
- ->diagnose (diag::distributed_actor_protocol_illegal_inheritance,
6082
- dc->getSelfNominalTypeDecl ()->getName ())
6083
- .fixItReplace (nominal->getStartLoc (), " distributed actor" );
6103
+ ->diagnose (diag::actor_protocol_illegal_inheritance,
6104
+ dc->getSelfNominalTypeDecl ()->getName (),
6105
+ proto->getName ())
6106
+ .fixItReplace (nominal->getStartLoc (), " actor" );
6084
6107
}
6085
6108
}
6109
+ break ;
6086
6110
}
6087
- } else if (proto->isSpecificProtocol (
6088
- KnownProtocolKind::DistributedActorSystem)) {
6089
- checkDistributedActorSystem (nominal);
6090
- } else if (proto->isSpecificProtocol (KnownProtocolKind::Actor)) {
6091
- if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6092
- if (!classDecl->isExplicitActor ()) {
6093
- dc->getSelfNominalTypeDecl ()
6094
- ->diagnose (diag::actor_protocol_illegal_inheritance,
6095
- dc->getSelfNominalTypeDecl ()->getName (),
6096
- proto->getName ())
6097
- .fixItReplace (nominal->getStartLoc (), " actor" );
6111
+ case KnownProtocolKind::AnyActor: {
6112
+ if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6113
+ if (!classDecl->isExplicitActor () &&
6114
+ !classDecl->isExplicitDistributedActor ()) {
6115
+ dc->getSelfNominalTypeDecl ()
6116
+ ->diagnose (diag::actor_protocol_illegal_inheritance,
6117
+ dc->getSelfNominalTypeDecl ()->getName (),
6118
+ proto->getName ())
6119
+ .fixItReplace (nominal->getStartLoc (), " actor" );
6120
+ }
6098
6121
}
6122
+ break ;
6123
+ }
6124
+ case KnownProtocolKind::UnsafeSendable: {
6125
+ hasDeprecatedUnsafeSendable = true ;
6126
+ break ;
6127
+ }
6128
+ case KnownProtocolKind::Executor: {
6129
+ tryDiagnoseExecutorConformance (Context, nominal, proto);
6130
+ break ;
6099
6131
}
6100
- } else if (proto->isSpecificProtocol (KnownProtocolKind::AnyActor)) {
6101
- if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6102
- if (!classDecl->isExplicitActor () &&
6103
- !classDecl->isExplicitDistributedActor ()) {
6104
- dc->getSelfNominalTypeDecl ()
6105
- ->diagnose (diag::actor_protocol_illegal_inheritance,
6106
- dc->getSelfNominalTypeDecl ()->getName (),
6107
- proto->getName ())
6108
- .fixItReplace (nominal->getStartLoc (), " actor" );
6132
+ case KnownProtocolKind::Copyable: {
6133
+ checkCopyableConformance (dc, ProtocolConformanceRef (conformance));
6134
+ break ;
6135
+ }
6136
+ case KnownProtocolKind::Escapable: {
6137
+ checkEscapableConformance (dc, ProtocolConformanceRef (conformance));
6138
+ break ;
6139
+ }
6140
+ case KnownProtocolKind::BitwiseCopyable: {
6141
+ if (Context.LangOpts .hasFeature (Feature::BitwiseCopyable)) {
6142
+ checkBitwiseCopyableConformance (
6143
+ conformance, /* isImplicit=*/ conformance->getSourceKind () ==
6144
+ ConformanceEntryKind::Synthesized);
6109
6145
}
6146
+ break ;
6147
+ }
6148
+ default :
6149
+ break ;
6110
6150
}
6111
- } else if (proto->isSpecificProtocol (
6112
- KnownProtocolKind::UnsafeSendable)) {
6113
- hasDeprecatedUnsafeSendable = true ;
6114
- } else if (proto->isSpecificProtocol (KnownProtocolKind::Executor)) {
6115
- tryDiagnoseExecutorConformance (Context, nominal, proto);
6116
- } else if (proto->isSpecificProtocol (KnownProtocolKind::Copyable)) {
6117
- checkCopyableConformance (dc, ProtocolConformanceRef (conformance));
6118
- } else if (proto->isSpecificProtocol (KnownProtocolKind::Escapable)) {
6119
- checkEscapableConformance (dc, ProtocolConformanceRef (conformance));
6120
- } else if (Context.LangOpts .hasFeature (Feature::BitwiseCopyable) &&
6121
- proto->isSpecificProtocol (KnownProtocolKind::BitwiseCopyable)) {
6122
- checkBitwiseCopyableConformance (
6123
- conformance, /* isImplicit=*/ conformance->getSourceKind () ==
6124
- ConformanceEntryKind::Synthesized);
6125
6151
}
6126
6152
}
6127
6153
0 commit comments