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