mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add Missing Definitions of canDerive{En,De}codable
This commit is contained in:
@@ -1071,10 +1071,35 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) {
|
||||
LLVM_FALLTHROUGH;
|
||||
case CodingKeysClassification::Valid:
|
||||
return true;
|
||||
static bool canDeriveCodable(NominalTypeDecl *NTD,
|
||||
KnownProtocolKind Kind) {
|
||||
assert(Kind == KnownProtocolKind::Encodable ||
|
||||
Kind == KnownProtocolKind::Decodable);
|
||||
|
||||
// Structs and classes can explicitly derive Encodable and Decodable
|
||||
// conformance (explicitly meaning we can synthesize an implementation if
|
||||
// a type conforms manually).
|
||||
// FIXME: Enums too!
|
||||
if (!isa<StructDecl>(NTD) && !isa<ClassDecl>(NTD)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto *PD = NTD->getASTContext().getProtocol(Kind);
|
||||
if (!PD) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DerivedConformance::canDeriveDecodable(NominalTypeDecl *NTD) {
|
||||
return canDeriveCodable(NTD, KnownProtocolKind::Decodable);
|
||||
}
|
||||
|
||||
bool DerivedConformance::canDeriveEncodable(NominalTypeDecl *NTD) {
|
||||
return canDeriveCodable(NTD, KnownProtocolKind::Encodable);
|
||||
}
|
||||
|
||||
ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
|
||||
// We can only synthesize Encodable for structs and classes.
|
||||
if (!isa<StructDecl>(Nominal) && !isa<ClassDecl>(Nominal))
|
||||
|
||||
Reference in New Issue
Block a user