Skip to content

PrintAsObjC: Fix crash when printing typedef that was imported inside an Objective-C generic class [5.3] #31948

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
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
2 changes: 1 addition & 1 deletion lib/PrintAsObjC/ModuleContentsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ReferencedTypeFinder : public TypeDeclFinder {
Action visitTypeAliasType(TypeAliasType *aliasTy) override {
if (aliasTy->getDecl()->hasClangNode() &&
!aliasTy->getDecl()->isCompatibilityAlias()) {
assert(!aliasTy->getGenericSignature());
assert(!aliasTy->getDecl()->isGeneric());
Callback(*this, aliasTy->getDecl());
} else {
Type(aliasTy->getSinglyDesugaredType()).walk(*this);
Expand Down
11 changes: 11 additions & 0 deletions test/PrintAsObjC/Inputs/imported-generic-typealias.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@interface NSObject
- (void) init;
@end;

@interface Horse<T> : NSObject
@end

@interface Barn : NSObject
@end

typedef int Hay __attribute__((swift_name("Horse.Hay")));
14 changes: 14 additions & 0 deletions test/PrintAsObjC/imported-generic-typealias.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)
// 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
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=CHECK-PUBLIC %s < %t/imported-generic-typealias.h

@objc public class MyRedBarn : Barn {
@objc public func feed(_: Horse<NSObject>.Hay) {}
}

// CHECK-LABEL: SWIFT_CLASS("_TtC4main9MyRedBarn")
// CHECK-NEXT: @interface MyRedBarn : Barn
// CHECK-NEXT: - (void)feed:(Hay)_;
// CHECK-NEXT: @end