@@ -83,14 +83,7 @@ static CodableConformanceType typeConformsToCodable(TypeChecker &tc,
83
83
DeclContext *context,
84
84
Type target, bool isIUO,
85
85
ProtocolDecl *proto) {
86
- target = context->mapTypeIntoContext (target->mapTypeOutOfContext ());
87
- // Some generic types need to be introspected to get at their "true" Codable
88
- // conformance.
89
- if (auto referenceType = target->getAs <ReferenceStorageType>()) {
90
- // This is a weak/unowned/unmanaged var. Get the inner type before checking
91
- // conformance.
92
- target = referenceType->getReferentType ();
93
- }
86
+ target = context->mapTypeIntoContext (target);
94
87
95
88
if (isIUO)
96
89
return typeConformsToCodable (tc, context, target->getOptionalObjectType (),
@@ -129,17 +122,18 @@ static CodableConformanceType varConformsToCodable(TypeChecker &tc,
129
122
// }
130
123
//
131
124
// Validate the decl eagerly.
132
- if (!varDecl->hasType ())
125
+ if (!varDecl->hasInterfaceType ())
133
126
tc.validateDecl (varDecl);
134
127
135
128
// If the var decl didn't validate, it may still not have a type; confirm it
136
129
// has a type before ensuring the type conforms to Codable.
137
- if (!varDecl->hasType ())
130
+ if (!varDecl->hasInterfaceType ())
138
131
return TypeNotValidated;
139
132
140
133
bool isIUO =
141
134
varDecl->getAttrs ().hasAttribute <ImplicitlyUnwrappedOptionalAttr>();
142
- return typeConformsToCodable (tc, context, varDecl->getType (), isIUO, proto);
135
+ return typeConformsToCodable (tc, context, varDecl->getValueInterfaceType (),
136
+ isIUO, proto);
143
137
}
144
138
145
139
// / Validates the given CodingKeys enum decl by ensuring its cases are a 1-to-1
@@ -522,8 +516,6 @@ static std::tuple<VarDecl *, Type, bool>
522
516
lookupVarDeclForCodingKeysCase (DeclContext *conformanceDC,
523
517
EnumElementDecl *elt,
524
518
NominalTypeDecl *targetDecl) {
525
- ASTContext &C = elt->getASTContext ();
526
-
527
519
for (auto decl : targetDecl->lookupDirect (DeclName (elt->getName ()))) {
528
520
if (auto *vd = dyn_cast<VarDecl>(decl)) {
529
521
if (!vd->isStatic ()) {
@@ -532,17 +524,11 @@ lookupVarDeclForCodingKeysCase(DeclContext *conformanceDC,
532
524
auto varType =
533
525
conformanceDC->mapTypeIntoContext (vd->getValueInterfaceType ());
534
526
535
- bool useIfPresentVariant =
536
- varType->getAnyNominal () == C.getOptionalDecl ();
537
-
538
- if (useIfPresentVariant) {
539
- // The type we request out of decodeIfPresent needs to be unwrapped
540
- // one level.
541
- // e.g. String? => decodeIfPresent(String.self, forKey: ...), not
542
- // decodeIfPresent(String?.self, forKey: ...)
543
- auto boundOptionalType =
544
- dyn_cast<BoundGenericType>(varType->getCanonicalType ());
545
- varType = boundOptionalType->getGenericArgs ()[0 ];
527
+ bool useIfPresentVariant = false ;
528
+
529
+ if (auto objType = varType->getOptionalObjectType ()) {
530
+ varType = objType;
531
+ useIfPresentVariant = true ;
546
532
}
547
533
548
534
return std::make_tuple (vd, varType, useIfPresentVariant);
0 commit comments