Skip to content

[Runtime] Fix gatherWrittenGenericArgs crashing when description is NULL #26936

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
Sep 9, 2019
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: 2 additions & 0 deletions stdlib/public/runtime/MetadataLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,8 @@ void swift::gatherWrittenGenericArgs(
const TypeContextDescriptor *description,
SmallVectorImpl<const Metadata *> &allGenericArgs,
Demangler &BorrowFrom) {
if (!description)
return;
auto generics = description->getGenericContext();
if (!generics)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

extension NSString {
class _Inner1<T> where T: NSObject {}
}

40 changes: 40 additions & 0 deletions test/Generics/generic-nested-in-extension-on-objc-class.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %empty-directory(%t)
// RUN: cp %s %t/main.swift
// RUN: %target-build-swift -module-name test %t/main.swift %S/inputs/generic-nested-in-extension-on-objc-class.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// REQUIRES: objc_interop

import Foundation

// Test the fix for a crash when instantiating the metadata for a generic type
// nested in an extension on an ObjC class in a different file.
// https://bugs.swift.org/browse/SR-11374

extension NSString {
class _Inner2<T> where T: NSObject {}
}

extension NSArray {
class Inner1: NSString._Inner1<NSArray> {
override init() {
super.init()
print("Inner1")
}
}
class Inner2: NSString._Inner2<NSArray> {
override init() {
super.init()
print("Inner2")
}
}
}

// CHECK: Inner1
_ = NSArray.Inner1()

// CHECK: Inner2
_ = NSArray.Inner2()