Skip to content

Commit d3f803e

Browse files
authored
Merge pull request #40597 from CodaFi/arggone
2 parents 2245ed4 + f475771 commit d3f803e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ static bool superclassConformsTo(ClassDecl *target, KnownProtocolKind kpk) {
5454
static Identifier getVarNameForCoding(VarDecl *var,
5555
Optional<int> paramIndex = None) {
5656
auto &C = var->getASTContext();
57-
Identifier identifier = var->getName();
57+
Identifier identifier;
58+
if (auto *PD = dyn_cast<ParamDecl>(var)) {
59+
identifier = PD->getArgumentName();
60+
} else {
61+
identifier = var->getName();
62+
}
63+
5864
if (auto originalVar = var->getOriginalWrappedProperty())
5965
identifier = originalVar->getName();
6066

test/decl/protocol/special/coding/enum_codable_simple.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum SimpleEnum : Codable {
66
case a(x: Int, y: Double)
77
case b(z: String)
88
case c(Int, String, b: Bool)
9+
case d(_ inner: Int)
910

1011
// These lines have to be within the SimpleEnum type because CodingKeys
1112
// should be private.
@@ -15,6 +16,7 @@ enum SimpleEnum : Codable {
1516
let _ = SimpleEnum.ACodingKeys.self
1617
let _ = SimpleEnum.BCodingKeys.self
1718
let _ = SimpleEnum.CCodingKeys.self
19+
let _ = SimpleEnum.DCodingKeys.self
1820

1921
// The enum should have a case for each of the cases.
2022
let _ = SimpleEnum.CodingKeys.a
@@ -29,6 +31,8 @@ enum SimpleEnum : Codable {
2931
let _ = SimpleEnum.CCodingKeys._0
3032
let _ = SimpleEnum.CCodingKeys._1
3133
let _ = SimpleEnum.CCodingKeys.b
34+
35+
let _ = SimpleEnum.DCodingKeys._0
3236
}
3337
}
3438

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend %s -emit-silgen
2+
3+
struct Boom: Decodable {}
4+
5+
enum Whiz: Decodable {
6+
case bang(_ boom: Boom)
7+
}

0 commit comments

Comments
 (0)