Skip to content

Commit 587a8da

Browse files
committed
Sema: Don't forget to visit conformances introduced by non-generic types
Even if a nominal type does not have its own generic parameters, we need to visit its conformances, because it might be defined in a constrained extension or have a 'where' clause of its own.
1 parent fa50221 commit 587a8da

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,20 @@ class ProblematicTypeFinder : public TypeDeclFinder {
30703070
Action visitNominalType(NominalType *ty) override {
30713071
visitTypeDecl(ty->getDecl());
30723072

3073-
/// FIXME
3073+
// If some generic parameters are missing, don't check conformances.
3074+
if (ty->hasUnboundGenericType())
3075+
return Action::Continue;
3076+
3077+
// When the DeclContext parameter to getContextSubstitutionMap()
3078+
// is a protocol declaration, the receiver must be a concrete
3079+
// type, so it doesn't make sense to perform this check on
3080+
// protocol types.
3081+
if (isa<ProtocolType>(ty))
3082+
return Action::Continue;
3083+
3084+
ModuleDecl *useModule = Where.getDeclContext()->getParentModule();
3085+
auto subs = ty->getContextSubstitutionMap(useModule, ty->getDecl());
3086+
(void) diagnoseSubstitutionMapAvailability(Loc, subs, Where);
30743087
return Action::Continue;
30753088
}
30763089

test/Sema/implementation-only-import-in-decls.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ public struct NormalProtoAssocHolder<T: NormalProto> {
179179
}
180180
public func testConformanceInBoundGeneric(_: NormalProtoAssocHolder<NormalStruct>) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
181181

182+
public struct OuterGenericHolder<T> {
183+
public struct Nested where T : NormalProto {
184+
public var value: T.Assoc
185+
}
186+
}
187+
public func testConformanceInNestedNonGeneric(_: OuterGenericHolder<NormalStruct>.Nested) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}
188+
182189
public class SubclassOfNormalClass: NormalClass {}
183190

184191
public func testInheritedConformance(_: NormalProtoAssocHolder<SubclassOfNormalClass>) {} // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' here; 'BADLibrary' has been imported as implementation-only}}

test/Sema/spi-in-decls.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ public struct NormalProtoAssocHolder<T: NormalProto> {
213213
}
214214
public func testConformanceInBoundGeneric(_: NormalProtoAssocHolder<NormalStruct>) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; the conformance is declared as SPI}}
215215

216+
public struct OuterGenericHolder<T> {
217+
public struct Nested where T : NormalProto {
218+
public var value: T.Assoc
219+
}
220+
}
221+
public func testConformanceInNestedNonGeneric(_: OuterGenericHolder<NormalStruct>.Nested) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; the conformance is declared as SPI}}
222+
216223
public class SubclassOfNormalClass: NormalClass {}
217224

218225
public func testInheritedConformance(_: NormalProtoAssocHolder<SubclassOfNormalClass>) {} // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' here; the conformance is declared as SPI}}

0 commit comments

Comments
 (0)