Skip to content

Commit 2795f40

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents 4e5ee3c + 91e4c0e commit 2795f40

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

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)