Skip to content

Commit 63f91d1

Browse files
committed
PrintAsObjC: Fix crash when printing typedef that was imported inside an Objective-C generic class
The assertion here is too strict. The TypeAliasDecl will inherit a generic signature from the outer context even if it does not have generic parameters of its own. Instead, let's just assert that the TypeAliasDecl does not have its own generic parameters. Fixes <rdar://problem/63188938>.
1 parent a242ad8 commit 63f91d1

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/PrintAsObjC/ModuleContentsWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ReferencedTypeFinder : public TypeDeclFinder {
5656
Action visitTypeAliasType(TypeAliasType *aliasTy) override {
5757
if (aliasTy->getDecl()->hasClangNode() &&
5858
!aliasTy->getDecl()->isCompatibilityAlias()) {
59-
assert(!aliasTy->getGenericSignature());
59+
assert(!aliasTy->getDecl()->isGeneric());
6060
Callback(*this, aliasTy->getDecl());
6161
} else {
6262
Type(aliasTy->getSinglyDesugaredType()).walk(*this);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@interface NSObject
2+
- (void) init;
3+
@end;
4+
5+
@interface Horse<T> : NSObject
6+
@end
7+
8+
@interface Barn : NSObject
9+
@end
10+
11+
typedef int Hay __attribute__((swift_name("Horse.Hay")));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: objc_interop
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/../Inputs/clang-importer-sdk -I %t) -parse-as-library %s -typecheck -emit-objc-header-path %t/imported-generic-typealias.h -import-objc-header %S/Inputs/imported-generic-typealias.h -disable-objc-attr-requires-foundation-module
5+
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=CHECK-PUBLIC %s < %t/imported-generic-typealias.h
6+
7+
@objc public class MyRedBarn : Barn {
8+
@objc public func feed(_: Horse<NSObject>.Hay) {}
9+
}
10+
11+
// CHECK-LABEL: SWIFT_CLASS("_TtC4main9MyRedBarn")
12+
// CHECK-NEXT: @interface MyRedBarn : Barn
13+
// CHECK-NEXT: - (void)feed:(Hay)_;
14+
// CHECK-NEXT: @end

0 commit comments

Comments
 (0)