Skip to content

Commit 7177055

Browse files
committed
[Refactoring] Skip failed witness decls in "add codable implementation"
When there are problems in the properties in the target type, witness methods may not be synthesized. Don't try to add such methods. #72387
1 parent 5d6ce70 commit 7177055

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/Refactoring/AddExplicitCodableImplementation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class AddCodableContext {
133133
kind == KnownProtocolKind::Decodable) {
134134
for (auto requirement : protocol->getProtocolRequirements()) {
135135
auto witness = conformance->getWitnessDecl(requirement);
136-
if (witness->isSynthesized()) {
136+
if (witness && witness->isSynthesized()) {
137137
Printer.printNewline();
138138
witness->print(Printer, Options);
139139
Printer.printNewline();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
struct Foo: Codable {
3+
var other: Unknown
4+
5+
private enum CodingKeys: CodingKey {
6+
case other
7+
}
8+
}
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %empty-directory(%t.result)
2+
3+
// RUN: %refactor -add-explicit-codable-implementation -source-filename %s -pos=%(line + 2):8 > %t.result/invalid_member.swift
4+
// RUN: diff -u %S/Outputs/has_error/invalid_member.swift.expected %t.result/invalid_member.swift
5+
struct Foo: Codable {
6+
var other: Unknown
7+
}
8+

0 commit comments

Comments
 (0)