Skip to content

[5.6] Use the API Name of Enum Parameters to Determine Coding Keys #40597

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 1 commit into from
Dec 17, 2021
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
8 changes: 7 additions & 1 deletion lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ static bool superclassConformsTo(ClassDecl *target, KnownProtocolKind kpk) {
static Identifier getVarNameForCoding(VarDecl *var,
Optional<int> paramIndex = None) {
auto &C = var->getASTContext();
Identifier identifier = var->getName();
Identifier identifier;
if (auto *PD = dyn_cast<ParamDecl>(var)) {
identifier = PD->getArgumentName();
} else {
identifier = var->getName();
}

if (auto originalVar = var->getOriginalWrappedProperty())
identifier = originalVar->getName();

Expand Down
4 changes: 4 additions & 0 deletions test/decl/protocol/special/coding/enum_codable_simple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum SimpleEnum : Codable {
case a(x: Int, y: Double)
case b(z: String)
case c(Int, String, b: Bool)
case d(_ inner: Int)

// These lines have to be within the SimpleEnum type because CodingKeys
// should be private.
Expand All @@ -15,6 +16,7 @@ enum SimpleEnum : Codable {
let _ = SimpleEnum.ACodingKeys.self
let _ = SimpleEnum.BCodingKeys.self
let _ = SimpleEnum.CCodingKeys.self
let _ = SimpleEnum.DCodingKeys.self

// The enum should have a case for each of the cases.
let _ = SimpleEnum.CodingKeys.a
Expand All @@ -29,6 +31,8 @@ enum SimpleEnum : Codable {
let _ = SimpleEnum.CCodingKeys._0
let _ = SimpleEnum.CCodingKeys._1
let _ = SimpleEnum.CCodingKeys.b

let _ = SimpleEnum.DCodingKeys._0
}
}

Expand Down
7 changes: 7 additions & 0 deletions validation-test/compiler_crashers_2_fixed/rdar86339848.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-swift-frontend %s -emit-silgen

struct Boom: Decodable {}

enum Whiz: Decodable {
case bang(_ boom: Boom)
}