@@ -61,14 +61,6 @@ static bool superclassIsDecodable(ClassDecl *target) {
61
61
C.getProtocol (KnownProtocolKind::Decodable));
62
62
}
63
63
64
- // / Represents the possible outcomes of checking whether a decl conforms to
65
- // / Encodable or Decodable.
66
- enum CodableConformanceType {
67
- TypeNotValidated,
68
- DoesNotConform,
69
- Conforms
70
- };
71
-
72
64
// / Returns whether the given type conforms to the given {En,De}codable
73
65
// / protocol.
74
66
// /
@@ -77,7 +69,7 @@ enum CodableConformanceType {
77
69
// / \param target The \c Type to validate.
78
70
// /
79
71
// / \param proto The \c ProtocolDecl to check conformance to.
80
- static CodableConformanceType typeConformsToCodable (DeclContext *context,
72
+ static ProtocolConformanceRef typeConformsToCodable (DeclContext *context,
81
73
Type target, bool isIUO,
82
74
ProtocolDecl *proto) {
83
75
target = context->mapTypeIntoContext (target);
@@ -86,8 +78,7 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
86
78
return typeConformsToCodable (context, target->getOptionalObjectType (),
87
79
false , proto);
88
80
89
- auto conf = TypeChecker::conformsToProtocol (target, proto, context, None);
90
- return conf.isInvalid () ? DoesNotConform : Conforms;
81
+ return TypeChecker::conformsToProtocol (target, proto, context, None);
91
82
}
92
83
93
84
// / Returns whether the given variable conforms to the given {En,De}codable
@@ -98,7 +89,7 @@ static CodableConformanceType typeConformsToCodable(DeclContext *context,
98
89
// / \param varDecl The \c VarDecl to validate.
99
90
// /
100
91
// / \param proto The \c ProtocolDecl to check conformance to.
101
- static CodableConformanceType
92
+ static ProtocolConformanceRef
102
93
varConformsToCodable (DeclContext *DC, VarDecl *varDecl, ProtocolDecl *proto) {
103
94
// If the decl doesn't yet have a type, we may be seeing it before the type
104
95
// checker has gotten around to evaluating its type. For example:
@@ -167,22 +158,13 @@ static bool validateCodingKeysEnum(DerivedConformance &derived,
167
158
// We have a property to map to. Ensure it's {En,De}codable.
168
159
auto conformance =
169
160
varConformsToCodable (conformanceDC, it->second , derived.Protocol );
170
- switch (conformance) {
171
- case Conforms:
172
- // The property was valid. Remove it from the list.
173
- properties.erase (it);
174
- break ;
175
-
176
- case DoesNotConform:
177
- it->second ->diagnose (diag::codable_non_conforming_property_here,
178
- derived.getProtocolType (), it->second ->getType ());
179
- LLVM_FALLTHROUGH;
180
-
181
- case TypeNotValidated:
182
- // We don't produce a diagnostic for a type which failed to validate.
183
- // This will produce a diagnostic elsewhere anyway.
184
- propertiesAreValid = false ;
185
- continue ;
161
+ if (conformance.isInvalid ()) {
162
+ it->second ->diagnose (diag::codable_non_conforming_property_here,
163
+ derived.getProtocolType (), it->second ->getType ());
164
+ propertiesAreValid = false ;
165
+ } else {
166
+ // The property was valid. Remove it from the list.
167
+ properties.erase (it);
186
168
}
187
169
}
188
170
@@ -341,28 +323,17 @@ static EnumDecl *synthesizeCodingKeysEnum(DerivedConformance &derived) {
341
323
// context, not the type.
342
324
auto conformance = varConformsToCodable (derived.getConformanceContext (),
343
325
varDecl, derived.Protocol );
344
- switch (conformance) {
345
- case Conforms:
346
- {
347
- auto *elt = new (C) EnumElementDecl (SourceLoc (),
348
- getVarNameForCoding (varDecl),
349
- nullptr , SourceLoc (), nullptr ,
350
- enumDecl);
351
- elt->setImplicit ();
352
- enumDecl->addMember (elt);
353
- break ;
354
- }
355
-
356
- case DoesNotConform:
357
- varDecl->diagnose (diag::codable_non_conforming_property_here,
358
- derived.getProtocolType (), varDecl->getType ());
359
- LLVM_FALLTHROUGH;
360
-
361
- case TypeNotValidated:
362
- // We don't produce a diagnostic for a type which failed to validate.
363
- // This will produce a diagnostic elsewhere anyway.
364
- allConform = false ;
365
- continue ;
326
+ if (conformance.isInvalid ()) {
327
+ varDecl->diagnose (diag::codable_non_conforming_property_here,
328
+ derived.getProtocolType (), varDecl->getType ());
329
+ allConform = false ;
330
+ } else {
331
+ auto *elt = new (C) EnumElementDecl (SourceLoc (),
332
+ getVarNameForCoding (varDecl),
333
+ nullptr , SourceLoc (), nullptr ,
334
+ enumDecl);
335
+ elt->setImplicit ();
336
+ enumDecl->addMember (elt);
366
337
}
367
338
}
368
339
@@ -1164,7 +1135,7 @@ ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
1164
1135
}
1165
1136
1166
1137
ValueDecl *DerivedConformance::deriveDecodable (ValueDecl *requirement) {
1167
- // We can only synthesize Encodable for structs and classes.
1138
+ // We can only synthesize Decodable for structs and classes.
1168
1139
if (!isa<StructDecl>(Nominal) && !isa<ClassDecl>(Nominal))
1169
1140
return nullptr ;
1170
1141
0 commit comments