Skip to content

[ClangImporter] Structs lexically in an ObjC class are still top-level. #10874

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 1 commit into from
Jul 11, 2017
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: 3 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8001,8 +8001,10 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
llvm::SmallPtrSet<Decl *, 4> knownAlternateMembers;
for (const clang::Decl *m : objcContainer->decls()) {
auto nd = dyn_cast<clang::NamedDecl>(m);
if (!nd || nd != nd->getCanonicalDecl())
if (!nd || nd != nd->getCanonicalDecl() ||
nd->getDeclContext() != objcContainer) {
continue;
}

forEachDistinctName(nd,
[&](ImportedName name, ImportNameVersion nameVersion) {
Expand Down
35 changes: 35 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/CInsideObjC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@interface Base
@end

struct AlreadyDeclaredStruct {
int value;
};

#if defined(CLASS)
@interface Wrapper : Base
#elif defined(CATEGORY)
@interface Wrapper : Base
@end
@interface Wrapper (Category)
#elif defined(PROTOCOL)
@protocol Wrapper
#else
# error "Must pick a variant"
#endif

extern void nestedFunc(void);

@property struct ForwardDeclaredStruct forward;
@property struct AlreadyDeclaredStruct backward;

struct NestedDeclaredStruct {
int value;
};
typedef int NestedTypedef;
extern const int nestedGlobal;

@end

struct ForwardDeclaredStruct {
int value;
};
5 changes: 5 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ module CFAndObjC {
export *
}

module CInsideObjC {
header "CInsideObjC.h"
export *
}

module ClangModuleUser {
header "ClangModuleUser.h"
export *
Expand Down
33 changes: 33 additions & 0 deletions test/ClangImporter/c_inside_objc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %target-swift-ide-test -print-module -module-to-print CInsideObjC -I %S/Inputs/custom-modules -source-filename %s -Xcc -DCLASS | %FileCheck %s
// RUN: %target-swift-ide-test -print-module -module-to-print CInsideObjC -I %S/Inputs/custom-modules -source-filename %s -Xcc -DCATEGORY | %FileCheck %s
// RUN: %target-swift-ide-test -print-module -module-to-print CInsideObjC -I %S/Inputs/custom-modules -source-filename %s -Xcc -DPROTOCOL | %FileCheck %s

// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -verify -Xcc -DCLASS
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -verify -Xcc -DCATEGORY
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -verify -Xcc -DPROTOCOL

// REQUIRES: objc_interop

// CHECK-LABEL: struct AlreadyDeclaredStruct {

// CHECK-LABEL: {{class Wrapper : Base {|extension Wrapper {|protocol Wrapper {}}
// CHECK-NOT: struct
// CHECK: var forward: ForwardDeclaredStruct
// CHECK-NOT: struct
// CHECK: var backward: AlreadyDeclaredStruct
// CHECK-NOT: struct
// CHECK: {{^}$}}

// CHECK-LABEL: func nestedFunc()
// CHECK-LABEL: struct NestedDeclaredStruct {
// CHECK-LABEL: typealias NestedTypedef = Int32
// CHECK-LABEL: let nestedGlobal: Int32

// CHECK-LABEL: struct ForwardDeclaredStruct {

import CInsideObjC

func testTypeLookup(_: AlreadyDeclaredStruct) {}
func testTypeLookup(_: NestedDeclaredStruct) {}
func testTypeLookup(_: ForwardDeclaredStruct) {}
func testTypeLookup(_: NestedTypedef) {}