Skip to content
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

[SR-15896] Generic NSObject subclasses fail to be realized when nested within function #58157

Open
matt-curtis opened this issue Feb 22, 2022 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself nested types Feature: nested types objective-c interop Feature: Interoperability with Objective-C

Comments

@matt-curtis
Copy link

Previous ID SR-15896
Radar https://feedbackassistant.apple.com/feedback/9921826
Original Reporter @matt-curtis
Type Bug
Environment

Swift version 5.5.2

Additional Detail from JIRA
Votes 1
Component/s Compiler, swift
Labels Bug
Assignee None
Priority Medium

md5: 01bac88df2cee847817186e8f82bfebb

Issue Description:

When a generic subclass of NSObject is declared within the body of a function, that class is never realized, and NSClassFromString returns nil. Demonstration:

//  Helper

func printClass(_ klass: NSObject.Type) {
    print(NSClassFromString(klass.className()))
}

//  Nested declaration of generic NSObject subclass. Fails:

({
    class NestedGenericNSObjectSubclass<T>: NSObject { }

    printClass(NestedGenericNSObjectSubclass<Int>.self) // nil
})()

//  Top-level declaration of generic NSObject subclass +
//  nested declaration of type. Fails:

class TopLevelGenericNSObjectSubclass<T>: NSObject { }

({
    enum SomeNestedType { }

    printClass(TopLevelGenericNSObjectSubclass<SomeNestedType>.self) // nil
})()

//  Works:

printClass(TopLevelGenericNSObjectSubclass<Int>.self) // TopLevelGenericNSObjectSubclass<Int>

Additional discussion on forums.swift.org.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added objective-c interop Feature: Interoperability with Objective-C nested types Feature: nested types and removed swift labels Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself nested types Feature: nested types objective-c interop Feature: Interoperability with Objective-C
Projects
None yet
Development

No branches or pull requests

2 participants