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

constructing an object of class type X with a metatype value must use a 'required' initializer #71874

Open
Kyle-Ye opened this issue Feb 25, 2024 · 0 comments · May be fixed by apple/swift-corelibs-foundation#4884
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@Kyle-Ye
Copy link
Collaborator

Kyle-Ye commented Feb 25, 2024

Description

The following code can compile on Darwin platform but on Linux platform we will get a compiler error.

swift build
Building for debugging...
DemoKit.swift:8:16: error: constructing an object of class type 'Delegate' with a metatype value must use a 'required' initializer
        return Delegate()
               ^~~~~~~~
Foundation.NSObject:2:12: note: selected non-required initializer 'init()'
    public init()
           ^
error: fatalError

Reproduction

Run swift package init to add a new empty package. And then update the main file to the following code.

import Foundation

class Box<Delegate: NSObject> {
    var delegate: NSObject {
        return Delegate()
    }
}

Expected behavior

Compile success on Linux.

Environment

swiftc --version
Swift version 5.9.2 (swift-5.9.2-RELEASE)
Target: aarch64-unknown-linux-gnu

uname -a
Linux ubuntu-2204 6.5.13-orbstack-00122-g57b8027e2387 #1 SMP Tue Feb  6 07:48:26 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Additional information

Forums discussion: https://forums.swift.org/t/nsobject-related-compile-issue-on-linux/70266/8

@Kyle-Ye Kyle-Ye added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 25, 2024
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. triage needed This issue needs more specific labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant