Skip to content

Commit 0991bcf

Browse files
committed
---
yaml --- r: 348701 b: refs/heads/master c: 2795f40 h: refs/heads/master i: 348699: 58d001c
1 parent 0a89e53 commit 0991bcf

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4e5ee3c6c0c5d4da39dc1b93e4bcaa16ff16349b
2+
refs/heads/master: 2795f40f33231faef9297b93c444695aa313f647
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/ClangImporter/ImportType.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -953,27 +953,32 @@ namespace {
953953
return {};
954954
}
955955
if (nsObjectTy && importedType->isEqual(nsObjectTy)) {
956-
SmallVector<clang::ObjCProtocolDecl *, 4> protocols{
957-
type->qual_begin(), type->qual_end()
958-
};
959-
auto *nsObjectProto =
960-
Impl.getNSObjectProtocolType()->getAnyNominal();
961-
if (!nsObjectProto) {
962-
// Input is malformed
963-
return {};
956+
// Skip if there is no NSObject protocol.
957+
auto nsObjectProtoType =
958+
Impl.getNSObjectProtocolType();
959+
if (nsObjectProtoType) {
960+
auto *nsObjectProto = nsObjectProtoType->getAnyNominal();
961+
if (!nsObjectProto) {
962+
// Input is malformed
963+
return {};
964+
}
965+
966+
SmallVector<clang::ObjCProtocolDecl *, 4> protocols{
967+
type->qual_begin(), type->qual_end()
968+
};
969+
auto *clangProto =
970+
cast<clang::ObjCProtocolDecl>(nsObjectProto->getClangDecl());
971+
protocols.push_back(
972+
const_cast<clang::ObjCProtocolDecl *>(clangProto));
973+
974+
clang::ASTContext &clangCtx = Impl.getClangASTContext();
975+
clang::QualType protosOnlyType =
976+
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy,
977+
/*type args*/{},
978+
protocols,
979+
/*kindof*/false);
980+
return Visit(clangCtx.getObjCObjectPointerType(protosOnlyType));
964981
}
965-
auto *clangProto =
966-
cast<clang::ObjCProtocolDecl>(nsObjectProto->getClangDecl());
967-
protocols.push_back(
968-
const_cast<clang::ObjCProtocolDecl *>(clangProto));
969-
970-
clang::ASTContext &clangCtx = Impl.getClangASTContext();
971-
clang::QualType protosOnlyType =
972-
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy,
973-
/*type args*/{},
974-
protocols,
975-
/*kindof*/false);
976-
return Visit(clangCtx.getObjCObjectPointerType(protosOnlyType));
977982
}
978983
}
979984

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Define our own NSObject interface, but not the protocol.
2+
@interface NSObject
3+
- nsobjectFunc;
4+
@end
5+
6+
@protocol FooProtocol
7+
- fooFunc;
8+
@end
9+
10+
typedef NSObject<FooProtocol> Foo;
11+
12+
@interface Bar : Foo
13+
- (instancetype)init;
14+
- (NSObject<FooProtocol> *)barFunc;
15+
@end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// Don't crash when there's no NSObject protocol.
2+
/// rdar://problem/34597302
3+
4+
// RUN: %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/no-nsobject-protocol.h -enable-objc-interop
5+
6+
var a = Bar()!
7+
var b = a.barFunc()!;
8+
b.nsobjectFunc()
9+
b.fooFunc()

0 commit comments

Comments
 (0)