Skip to content

Commit 88f9ab0

Browse files
committed
[Sema] Properly handle generics in enum Codable synthesis
rdar://79916494
1 parent e432296 commit 88f9ab0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,9 @@ deriveBodyEncodable_enum_encode(AbstractFunctionDecl *encodeDecl, void *) {
11461146
}
11471147

11481148
// generate: case .<Case>:
1149+
auto enumType = funcDC->mapTypeIntoContext(enumDecl->getDeclaredInterfaceType());
11491150
auto pat = new (C) EnumElementPattern(
1150-
TypeExpr::createImplicit(enumDecl->getDeclaredType(), C), SourceLoc(),
1151+
TypeExpr::createImplicit(enumType, C), SourceLoc(),
11511152
DeclNameLoc(), DeclNameRef(), elt, subpattern);
11521153
pat->setImplicit();
11531154

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Container<Element> {
4+
let options: [Option]
5+
}
6+
7+
extension Container {
8+
enum Option {
9+
case first (Element)
10+
case second (Element)
11+
}
12+
}
13+
14+
extension Container: Codable where Element: Codable {}
15+
extension Container.Option: Codable where Element: Codable {}

0 commit comments

Comments
 (0)