Skip to content

Conversation

@calda
Copy link
Contributor

@calda calda commented Dec 31, 2025

Corresponding Swift Syntax PR: swiftlang/swift-syntax#3223

Swift evolution pitch: https://forums.swift.org/t/support-trailing-closure-syntax-for-single-argument-array-and-dictionary-initializers/83900


This PR prototypes support for array and dictionary expression trailing closure syntax.

Today, if you have an @ArrayBuilder type and define:

extension Array {
  init(@ArrayBuilder<Element> _ build: () -> [Element]) {
    self = build()
  }
}

you currently cannot call it like this:

let myArray = [String] { // error: 'let' declarations cannot be computed properties
  "foo"
  "bar"
}

This PR enables support for that syntax by allowing trailing closures following array literals.

@calda calda changed the title Support '[Element] { ... }' trailing closure init syntax Support [Element] { ... } trailing closure init syntax Dec 31, 2025
@calda calda force-pushed the cal--array-init-trailing-closure branch from 53538a2 to c042e5f Compare December 31, 2025 21:31
@calda calda force-pushed the cal--array-init-trailing-closure branch from c042e5f to 365ab62 Compare December 31, 2025 21:36
@vanvoorden
Copy link
Contributor

@calda Want to try a toolchain build for engineers to experiment with?

@calda
Copy link
Contributor Author

calda commented Jan 2, 2026

That would be great. I would need somebody to trigger the build, since I don't have write access.

@vanvoorden
Copy link
Contributor

@swift-ci Please Build Toolchain macOS Platform

@calda
Copy link
Contributor Author

calda commented Jan 4, 2026

@vanvoorden, could you also run the source compatibility tests? Thanks!

@vanvoorden
Copy link
Contributor

@swift-ci Please Test Source Compatibility Debug

@calda calda changed the title Support [Element] { ... } trailing closure init syntax Support array expression trailing closures Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants