Skip to content

Commit d5bbac9

Browse files
committed
Bring back the convenience initializer and deprecate it. Add entries to release notes.
1 parent 22347b8 commit d5bbac9

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

Release Notes/601.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
- `Error` protocol now has an `asDiagnostics(at:)` method.
1515
- Description: This method translates an error into one or more diagnostics, recognizing `DiagnosticsError` and `DiagnosticMessage` instances or providing its own `Diagnostic` as needed.
1616
- Pull Request: https://github.com/swiftlang/swift-syntax/pull/1816
17+
18+
- `ClosureCaptureSyntax` now has a new node structure.
19+
- Description: `ClosureCaptureSyntax` now has an `initializer` property instead of `equal` and `expression`. Additionally, the `name` property is no longer optional.
20+
- Pull request: https://github.com/swiftlang/swift-syntax/pull/2763
1721

1822
## API Behavior Changes
1923

@@ -27,6 +31,10 @@
2731
- Description: `IncrementalEdit` is being dropped for `SourceEdit`. `SourceEdit` has deprecated compatibility layers to make it API-compatible with `IncrementalEdit`
2832
- Issue: https://github.com/apple/swift-syntax/issues/2532
2933
- Pull request: https://github.com/apple/swift-syntax/pull/2604
34+
35+
- `ClosureCaptureSyntax.init(leadingTrivia:specifier:name:equal:expression:trailingComma:trailingTrivia:)` deprecated in favor of a new `ClosureCaptureSyntax.init(leadingTrivia:_:specifier:_:name:_:initializer:_:trailingComma:_:trailingTrivia:)` initializer.
36+
- Description: The change is due to a new `ClosureCaptureSyntax` node structure.
37+
- Pull request: https://github.com/swiftlang/swift-syntax/pull/2763
3038

3139
## API-Incompatible Changes
3240

Sources/SwiftParser/Expressions.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,26 +1705,20 @@ extension Parser {
17051705

17061706
// The thing being capture specified is an identifier, or as an identifier
17071707
// followed by an initializer clause.
1708-
let unexpectedBeforeName: RawUnexpectedNodesSyntax?
1709-
let name: RawTokenSyntax
1708+
let (unexpectedBeforeName, name) = self.expect(
1709+
.identifier,
1710+
TokenSpec(.self),
1711+
default: .identifier
1712+
)
1713+
17101714
let initializer: RawInitializerClauseSyntax?
1711-
if self.peek(isAt: .equal) {
1715+
if self.at(.equal) {
17121716
// The name is a new declaration with
17131717
// initializer clause.
1714-
(unexpectedBeforeName, name) = self.expect(
1715-
.identifier,
1716-
TokenSpec(.self, remapping: .identifier),
1717-
default: .identifier
1718-
)
17191718
initializer = self.parseInitializerClause()
17201719
} else {
17211720
// This is the simple case - the identifier is the name and
17221721
// the initializer clause is empty.
1723-
(unexpectedBeforeName, name) = self.expect(
1724-
.identifier,
1725-
TokenSpec(.self),
1726-
default: .identifier
1727-
)
17281722
initializer = nil
17291723
}
17301724

Sources/SwiftSyntax/Convenience.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
extension ClosureCaptureSyntax {
14+
15+
/// Creates a ``ClosureCaptureSyntax`` with a `name`, and automatically adds an `equal` token to it since the name is non-optional.
16+
///
17+
/// - SeeAlso: ``ClosureCaptureSyntax/init(leadingTrivia:_:specifier:_:name:_:initializer:_:trailingComma:_:trailingTrivia:)``.
18+
///
19+
@available(
20+
*,
21+
deprecated,
22+
message: "Use 'init(leadingTrivia:_:specifier:_:name:_:initializer:_:trailingComma:_:trailingTrivia:)' instead"
23+
)
24+
public init(
25+
leadingTrivia: Trivia? = nil,
26+
specifier: ClosureCaptureSpecifierSyntax? = nil,
27+
name: TokenSyntax,
28+
equal: TokenSyntax = TokenSyntax.equalToken(),
29+
expression: some ExprSyntaxProtocol,
30+
trailingComma: TokenSyntax? = nil,
31+
trailingTrivia: Trivia? = nil
32+
) {
33+
self.init(
34+
leadingTrivia: leadingTrivia,
35+
specifier: specifier,
36+
name: name,
37+
initializer: InitializerClauseSyntax(equal: equal, value: expression),
38+
trailingComma: trailingComma,
39+
trailingTrivia: trailingTrivia
40+
)
41+
}
42+
}
43+
1344
extension EnumCaseParameterSyntax {
1445

1546
/// Creates an ``EnumCaseParameterSyntax`` with a `firstName`, and automatically adds a `colon` to it.

0 commit comments

Comments
 (0)