Merge pull request #82238 from slavapestov/coding-keys-parameter-pack

Sema: Relax enum parameter pack restriction for CodingKeys
This commit is contained in:
Slava Pestov
2025-06-17 07:48:35 -04:00
committed by GitHub
5 changed files with 20 additions and 6 deletions

View File

@@ -6366,6 +6366,9 @@ ConstructorDecl *NominalTypeDecl::getDefaultInitializer() const {
}
void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
if (isa<ProtocolDecl>(this))
return;
// Silently break cycles here because we can't be sure when and where a
// request to synthesize will come from yet.
// FIXME: rdar://56844567

View File

@@ -1364,6 +1364,8 @@ evaluator::SideEffect
ResolveImplicitMemberRequest::evaluate(Evaluator &evaluator,
NominalTypeDecl *target,
ImplicitMemberAction action) const {
ASSERT(!isa<ProtocolDecl>(target));
// FIXME: This entire request is a layering violation made of smaller,
// finickier layering violations. See rdar://56844567

View File

@@ -2941,7 +2941,7 @@ static ArrayRef<Decl *> evaluateMembersRequest(
}
}
if (nominal) {
if (nominal && !isa<ProtocolDecl>(nominal)) {
// If the type conforms to Encodable or Decodable, even via an extension,
// the CodingKeys enum is synthesized as a member of the type itself.
// Force it into existence.

View File

@@ -3226,11 +3226,13 @@ public:
// Temporary restriction until we figure out pattern matching and
// enum case construction with packs.
if (auto genericSig = ED->getGenericSignature()) {
for (auto paramTy : genericSig.getGenericParams()) {
if (paramTy->isParameterPack()) {
ED->diagnose(diag::enum_with_pack);
break;
if (!ED->isSynthesized()) {
if (auto genericSig = ED->getGenericSignature()) {
for (auto paramTy : genericSig.getGenericParams()) {
if (paramTy->isParameterPack()) {
ED->diagnose(diag::enum_with_pack);
break;
}
}
}
}

View File

@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple
// We should accept this:
public struct HasPack<each T>: Codable {
var x: String?
}