Skip to content

Commit de3fb02

Browse files
authored
Merge pull request #82238 from slavapestov/coding-keys-parameter-pack
Sema: Relax enum parameter pack restriction for CodingKeys
2 parents 8acde34 + 9a101ca commit de3fb02

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6366,6 +6366,9 @@ ConstructorDecl *NominalTypeDecl::getDefaultInitializer() const {
63666366
}
63676367

63686368
void NominalTypeDecl::synthesizeSemanticMembersIfNeeded(DeclName member) {
6369+
if (isa<ProtocolDecl>(this))
6370+
return;
6371+
63696372
// Silently break cycles here because we can't be sure when and where a
63706373
// request to synthesize will come from yet.
63716374
// FIXME: rdar://56844567

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ evaluator::SideEffect
13641364
ResolveImplicitMemberRequest::evaluate(Evaluator &evaluator,
13651365
NominalTypeDecl *target,
13661366
ImplicitMemberAction action) const {
1367+
ASSERT(!isa<ProtocolDecl>(target));
1368+
13671369
// FIXME: This entire request is a layering violation made of smaller,
13681370
// finickier layering violations. See rdar://56844567
13691371

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ static ArrayRef<Decl *> evaluateMembersRequest(
29412941
}
29422942
}
29432943

2944-
if (nominal) {
2944+
if (nominal && !isa<ProtocolDecl>(nominal)) {
29452945
// If the type conforms to Encodable or Decodable, even via an extension,
29462946
// the CodingKeys enum is synthesized as a member of the type itself.
29472947
// Force it into existence.

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,11 +3226,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32263226

32273227
// Temporary restriction until we figure out pattern matching and
32283228
// enum case construction with packs.
3229-
if (auto genericSig = ED->getGenericSignature()) {
3230-
for (auto paramTy : genericSig.getGenericParams()) {
3231-
if (paramTy->isParameterPack()) {
3232-
ED->diagnose(diag::enum_with_pack);
3233-
break;
3229+
if (!ED->isSynthesized()) {
3230+
if (auto genericSig = ED->getGenericSignature()) {
3231+
for (auto paramTy : genericSig.getGenericParams()) {
3232+
if (paramTy->isParameterPack()) {
3233+
ED->diagnose(diag::enum_with_pack);
3234+
break;
3235+
}
32343236
}
32353237
}
32363238
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple
2+
3+
// We should accept this:
4+
5+
public struct HasPack<each T>: Codable {
6+
var x: String?
7+
}

0 commit comments

Comments
 (0)