Skip to content

Commit fbf5a51

Browse files
authored
[ClangImporter] Test for not being in a module correctly. (#9992)
For the Optional<Module *> returned by getClangSubmoduleForDecl, the outside Optional specifies whether there's an answer at all. That answer can still be null if the declaration comes from a bridging header. In this particular case, we're guaranteed to get an answer, but that answer may be null. rdar://problem/32463543
1 parent 8d1e234 commit fbf5a51

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,10 +1768,10 @@ shouldSuppressGenericParamsImport(const LangOptions &langOpts,
17681768
// the SwiftImportAsNonGeneric API note. Once we can guarantee that that
17691769
// attribute is present in all contexts, we can remove this check.
17701770
auto isFromFoundationModule = [](const clang::Decl *decl) -> bool {
1771-
Optional<clang::Module *> module = getClangSubmoduleForDecl(decl);
1771+
clang::Module *module = getClangSubmoduleForDecl(decl).getValue();
17721772
if (!module)
17731773
return false;
1774-
return module.getValue()->getTopLevelModuleName() == "Foundation";
1774+
return module->getTopLevelModuleName() == "Foundation";
17751775
};
17761776

17771777
if (langOpts.isSwiftVersion3() || isFromFoundationModule(decl)) {

test/ClangImporter/MixedSource/Inputs/mixed-target/header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ typedef int NameInCategory;
7575
@interface ClassThatHasAProtocolTypedPropertyButMembersAreNeverLoaded
7676
@property (weak) id <ForwardProtoFromOtherFile> weakProtoProp;
7777
@end
78+
79+
80+
@interface GenericObjCClass<Param : id <ForwardProto>> : Base
81+
- (instancetype)init;
82+
@end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/../Inputs/custom-modules -import-objc-header %S/Inputs/mixed-target/header.h -typecheck -primary-file %S/mixed-target-using-header.swift %S/Inputs/mixed-target/other-file.swift -disable-objc-attr-requires-foundation-module -verify -swift-version 4
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/../Inputs/custom-modules -import-objc-header %S/Inputs/mixed-target/header.h -emit-sil -primary-file %S/mixed-target-using-header.swift %S/Inputs/mixed-target/other-file.swift -disable-objc-attr-requires-foundation-module -o /dev/null -D SILGEN -swift-version 4
3+
4+
// REQUIRES: objc_interop

test/ClangImporter/MixedSource/mixed-target-using-header.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func testProtocolNamingConflict() {
7575
d = c // expected-error {{cannot assign value of type 'ConflictingName2?' to type 'ConflictingName2Protocol?'}}
7676
_ = d
7777
}
78+
79+
func testObjCGenerics() {
80+
_ = GenericObjCClass<ForwardProtoAdopter>()
81+
_ = GenericObjCClass<Base>() // expected-error {{type 'Base' does not conform to protocol 'ForwardProto'}}
82+
}
7883
#endif
7984

8085
func testDeclsNestedInObjCContainers() {

0 commit comments

Comments
 (0)