File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed
test/decl/protocol/special/coding Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -728,6 +728,8 @@ LookupConformanceInModuleRequest::evaluate(
728
728
ProtocolConformanceRef
729
729
ModuleDecl::checkConformance (Type type, ProtocolDecl *proto,
730
730
bool allowMissing) {
731
+ assert (!type->hasTypeParameter ());
732
+
731
733
auto lookupResult = lookupConformance (type, proto, allowMissing);
732
734
if (lookupResult.isInvalid ()) {
733
735
return ProtocolConformanceRef::forInvalid ();
Original file line number Diff line number Diff line change @@ -174,8 +174,19 @@ void ConformingMethodListCallbacks::getMatchingMethods(
174
174
if (FD->isStatic () || FD->isOperator ())
175
175
return false ;
176
176
177
- auto resultTy = T->getTypeOfMember (CurModule, FD,
178
- FD->getResultInterfaceType ());
177
+ assert (!T->hasTypeParameter ());
178
+
179
+ // T may contain primary archetypes from some fixed generic signature G.
180
+ // This might be unrelated to the generic signature of FD. However if
181
+ // FD has a generic parameter of its own and it returns a type containing
182
+ // that parameter, we want to map it to the corresponding archetype
183
+ // from the generic environment of FD, because all we do with the
184
+ // resulting type is check conformance. If the conformance is conditional,
185
+ // we might run into trouble with really complicated cases but the fake
186
+ // archetype setup will mostly work.
187
+ auto substitutions = T->getMemberSubstitutionMap (
188
+ CurModule, FD, FD->getGenericEnvironment ());
189
+ auto resultTy = FD->getResultInterfaceType ().subst (substitutions);
179
190
if (resultTy->is <ErrorType>())
180
191
return false ;
181
192
Original file line number Diff line number Diff line change @@ -1396,7 +1396,7 @@ static void diagnoseClassWithoutInitializers(ClassDecl *classDecl) {
1396
1396
if (auto *superclassDecl = classDecl->getSuperclassDecl ()) {
1397
1397
auto *decodableProto = C.getProtocol (KnownProtocolKind::Decodable);
1398
1398
auto superclassType = superclassDecl->getDeclaredInterfaceType ();
1399
- auto ref = classDecl->getParentModule ()->checkConformance (
1399
+ auto ref = classDecl->getParentModule ()->lookupConformance (
1400
1400
superclassType, decodableProto);
1401
1401
if (ref) {
1402
1402
// super conforms to Decodable, so we've failed to inherit init(from:).
@@ -1425,7 +1425,7 @@ static void diagnoseClassWithoutInitializers(ClassDecl *classDecl) {
1425
1425
// likely that the user forgot to override its encode(to:). In this case,
1426
1426
// we can produce a slightly different diagnostic to suggest doing so.
1427
1427
auto *encodableProto = C.getProtocol (KnownProtocolKind::Encodable);
1428
- auto ref = classDecl->getParentModule ()->checkConformance (
1428
+ auto ref = classDecl->getParentModule ()->lookupConformance (
1429
1429
superclassType, encodableProto);
1430
1430
if (ref) {
1431
1431
// We only want to produce this version of the diagnostic if the
Original file line number Diff line number Diff line change @@ -97,3 +97,13 @@ class EncodableSubWithoutInitialValue : CodableSuper { // expected-error {{class
97
97
class CodableSubWithInitialValue : CodableSuper {
98
98
var value2 = 10
99
99
}
100
+
101
+ class GenericCodableSuper < T> : Decodable { }
102
+
103
+ class GenericCodableSub < T> : GenericCodableSuper < T > {
104
+ // expected-error@-1 {{class 'GenericCodableSub' has no initializers}}
105
+ // expected-note@-2 {{did you mean to override 'init(from:)'?}}
106
+ // expected-warning@-2 {{'required' initializer 'init(from:)' must be provided by subclass of 'GenericCodableSuper<T>'; this is an error in Swift 6}}
107
+ var t : T
108
+ // expected-note@-1 {{stored property 't' without initial value prevents synthesized initializers}}
109
+ }
You can’t perform that action at this time.
0 commit comments