Skip to content
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
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2795,7 +2795,7 @@ WARNING(differentiable_let_property_implicit_noderivative_fixit,none,
NOTE(codable_extraneous_codingkey_case_here,none,
"CodingKey case %0 does not match any stored properties", (Identifier))
NOTE(codable_non_conforming_property_here,none,
"cannot automatically synthesize %0 because %1 does not conform to %0", (Type, Type))
"cannot automatically synthesize %0 because %1 does not conform to %0", (Type, TypeLoc))
NOTE(codable_non_decoded_property_here,none,
"cannot automatically synthesize %0 because %1 does not have a matching CodingKey and does not have a default value", (Type, Identifier))
NOTE(codable_codingkeys_type_is_not_an_enum_here,none,
Expand Down
28 changes: 24 additions & 4 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,20 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
properties.erase(it);
break;

case DoesNotConform:
case DoesNotConform: {
// We use a TypeLoc here so diagnostics can show the type
// as written by the user in source if possible. This is useful
// when the user has written an IUO type for example, since
// diagnostics would show the type as 'T?' instead of 'T!' if
// we use a Type instead.
TypeLoc typeLoc = {
it->second->getTypeReprOrParentPatternTypeRepr(),
it->second->getType(),
};
it->second->diagnose(diag::codable_non_conforming_property_here,
derived.getProtocolType(), it->second->getType());
derived.getProtocolType(), typeLoc);
LLVM_FALLTHROUGH;
}

case TypeNotValidated:
// We don't produce a diagnostic for a type which failed to validate.
Expand Down Expand Up @@ -352,10 +362,20 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
break;
}

case DoesNotConform:
case DoesNotConform: {
// We use a TypeLoc here so diagnostics can show the type
// as written by the user in source if possible. This is useful
// when the user has written an IUO type for example, since
// diagnostics would show the type as 'T?' instead of 'T!' if
// we use a Type instead.
TypeLoc typeLoc = {
varDecl->getTypeReprOrParentPatternTypeRepr(),
varDecl->getType(),
};
varDecl->diagnose(diag::codable_non_conforming_property_here,
derived.getProtocolType(), varDecl->getType());
derived.getProtocolType(), typeLoc);
LLVM_FALLTHROUGH;
}

case TypeNotValidated:
// We don't produce a diagnostic for a type which failed to validate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class ClassWithNonExcludedVarMembers : Codable { // expected-error {{type 'Class
// AnyHashable does not conform to Codable.
var p3: AnyHashable? // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
var p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
var p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable!' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable!' does not conform to 'Encodable'}}
}

class ClassWithExcludedVarMembers : Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class C1 : Codable {
var a: String = ""
var b: Int = 0
var c: Nested = Nested()
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'C1.Nested' does not conform to 'Decodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'C1.Nested' does not conform to 'Encodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'Nested' does not conform to 'Decodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'Nested' does not conform to 'Encodable'}}
}

// Codable class with non-enum CodingKeys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct StructWithNonExcludedLetMembers : Codable { // expected-error {{type 'Str
// AnyHashable does not conform to Codable.
let p3: AnyHashable? // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
let p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
let p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable!' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable!' does not conform to 'Encodable'}}
}

struct StructWithExcludedLetMembers : Codable { // expected-error {{type 'StructWithExcludedLetMembers' does not conform to protocol 'Decodable'}}
Expand Down Expand Up @@ -46,8 +46,8 @@ struct StructWithNonExcludedVarMembers : Codable { // expected-error {{type 'Str
// AnyHashable does not conform to Codable.
var p3: AnyHashable? // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
var p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable?' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable?' does not conform to 'Encodable'}}
var p4: AnyHashable! // expected-note {{cannot automatically synthesize 'Decodable' because 'AnyHashable!' does not conform to 'Decodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'AnyHashable!' does not conform to 'Encodable'}}
}

struct StructWithExcludedVarMembers : Codable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct S1 : Codable {
var a: String = ""
var b: Int = 0
var c: Nested = Nested()
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'S1.Nested' does not conform to 'Decodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'S1.Nested' does not conform to 'Encodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Decodable' because 'Nested' does not conform to 'Decodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'Nested' does not conform to 'Encodable'}}
}

// Codable struct with non-enum CodingKeys.
Expand Down
4 changes: 2 additions & 2 deletions test/decl/protocol/special/coding/struct_codable_simple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ let _ = SimpleStruct.CodingKeys.self // expected-error {{'CodingKeys' is inacces
struct SR_12248_1: Codable { // expected-error {{type 'SR_12248_1' does not conform to protocol 'Encodable'}}
var x: Int // expected-note {{'x' previously declared here}}
var x: Int // expected-error {{invalid redeclaration of 'x'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because '<<error type>>' does not conform to 'Encodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because '<<error type>>' does not conform to 'Encodable'}}
// expected-note@-1 {{cannot automatically synthesize 'Encodable' because 'Int' does not conform to 'Encodable'}}
// expected-note@-2 {{cannot automatically synthesize 'Encodable' because 'Int' does not conform to 'Encodable'}}
}

struct SR_12248_2: Decodable {
Expand Down