Skip to content

[ClangImporter] Test for not being in a module correctly. #9992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,10 +1768,10 @@ shouldSuppressGenericParamsImport(const LangOptions &langOpts,
// the SwiftImportAsNonGeneric API note. Once we can guarantee that that
// attribute is present in all contexts, we can remove this check.
auto isFromFoundationModule = [](const clang::Decl *decl) -> bool {
Optional<clang::Module *> module = getClangSubmoduleForDecl(decl);
clang::Module *module = getClangSubmoduleForDecl(decl).getValue();
if (!module)
return false;
return module.getValue()->getTopLevelModuleName() == "Foundation";
return module->getTopLevelModuleName() == "Foundation";
};

if (langOpts.isSwiftVersion3() || isFromFoundationModule(decl)) {
Expand Down
5 changes: 5 additions & 0 deletions test/ClangImporter/MixedSource/Inputs/mixed-target/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ typedef int NameInCategory;
@interface ClassThatHasAProtocolTypedPropertyButMembersAreNeverLoaded
@property (weak) id <ForwardProtoFromOtherFile> weakProtoProp;
@end


@interface GenericObjCClass<Param : id <ForwardProto>> : Base
- (instancetype)init;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 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
// 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

// REQUIRES: objc_interop
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func testProtocolNamingConflict() {
d = c // expected-error {{cannot assign value of type 'ConflictingName2?' to type 'ConflictingName2Protocol?'}}
_ = d
}

func testObjCGenerics() {
_ = GenericObjCClass<ForwardProtoAdopter>()
_ = GenericObjCClass<Base>() // expected-error {{type 'Base' does not conform to protocol 'ForwardProto'}}
}
#endif

func testDeclsNestedInObjCContainers() {
Expand Down