Skip to content

Sema: Relax enum parameter pack restriction for CodingKeys #82238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6363,6 +6363,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
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3226,11 +3226,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

// 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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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?
}