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

Cannot use Array shorthand notation when calling single-param initializer with trailing closure #78843

Open
lukaskollmer opened this issue Jan 23, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@lukaskollmer
Copy link

lukaskollmer commented Jan 23, 2025

Description

Creating an array via an initializer that takes a trailing closure only compiles when using the explicit notation (i.e. Array<T>, but doesn't compile when using the shorthand notation (i.e. [T]).

If the initializer takes additional parameters prior to the trailing closure, both notations work fine.

Reproduction

extension Array {
    init(_ element: () -> Element) {
        self.init()
        append(element())
    }

    init(dummy: Void, element: () -> Element) {
        self.init()
        append(element())
    }
}

let a1 = Array<String> { "hey" } // ok
let a2 = [String] { "hey" } // doesn't compile

let b1 = Array<String>(dummy: ()) { "hey" } // ok
let b2 = [String](dummy: ()) { "hey" } // ok

Expected behavior

both should work

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

No response

@lukaskollmer lukaskollmer added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 23, 2025
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

No branches or pull requests

1 participant