Skip to content

Address review comments for API compatibility of ThrowsClauseSyntax #2393

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Release Notes/511.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
- The new classification case covers the first names of parameters in function-like declarations and the label of arguments in function-like calls.
- Pull request: https://github.com/apple/swift-syntax/pull/2375
- Migration steps: In exhaustive switches over `SyntaxClassification`, cover the new case.

- `SyntaxEnum` and `SyntaxKind` gained new cases: `throwsClause`
- The new cases cover the newly introduced `ThrowsClauseSyntax`
- Pull request: https://github.com/apple/swift-syntax/pull/2379
- Migration steps: In exhaustive switches over `SyntaxEnum` and `SyntaxKind`, cover the new case.


## Template

Expand Down
4 changes: 1 addition & 3 deletions Sources/SwiftParser/Specifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ extension TokenConsumer {
extension Parser {
/// Parse a throws clause after we've already parsed the 'throws' keyword to introduce it.
mutating func parseThrowsClause(after throwsKeyword: RawTokenSyntax) -> RawThrowsClauseSyntax {
guard self.at(.leftParen) && experimentalFeatures.contains(.typedThrows) else {
guard experimentalFeatures.contains(.typedThrows), let leftParen = self.consume(if: .leftParen) else {
return RawThrowsClauseSyntax(
throwsSpecifier: throwsKeyword,
leftParen: nil,
Expand All @@ -594,12 +594,10 @@ extension Parser {
)
}

let (unexpectedBetweenThrowsSpecifierAndLeftParen, leftParen) = self.expect(.leftParen)
let type = self.parseType()
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
return RawThrowsClauseSyntax(
throwsSpecifier: throwsKeyword,
unexpectedBetweenThrowsSpecifierAndLeftParen,
leftParen: leftParen,
type: type,
unexpectedBeforeRightParen,
Expand Down
32 changes: 32 additions & 0 deletions Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
// All users of the declarations in this file should transition away from them ASAP.

public extension AccessorEffectSpecifiersSyntax {
@_disfavoredOverload
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
asyncSpecifier: TokenSyntax? = nil,
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
throwsSpecifier: TokenSyntax? = nil,
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeAsyncSpecifier,
asyncSpecifier: asyncSpecifier,
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
unexpectedAfterThrowsSpecifier,
trailingTrivia: trailingTrivia
)
}
Expand Down Expand Up @@ -68,6 +75,12 @@ public extension DeclGroupSyntax {
}

public extension EffectSpecifiersSyntax {
@available(*, deprecated, renamed: "unexpectedBetweenAsyncSpecifierAndThrowsClause")
var unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? {
get { unexpectedBetweenAsyncSpecifierAndThrowsClause }
set { unexpectedBetweenAsyncSpecifierAndThrowsClause = newValue }
}

@available(*, deprecated, message: "use throwsClause.throwsSpecifier")
var throwsSpecifier: TokenSyntax? {
get { throwsClause?.throwsSpecifier }
Expand All @@ -85,20 +98,33 @@ public extension EffectSpecifiersSyntax {
}
}
}

@available(*, deprecated, renamed: "unexpectedAfterThrowsClause")
var unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? {
get { unexpectedAfterThrowsClause }
set { unexpectedAfterThrowsClause = newValue }
}
}

public extension FunctionEffectSpecifiersSyntax {
@_disfavoredOverload
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
asyncSpecifier: TokenSyntax? = nil,
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
throwsSpecifier: TokenSyntax? = nil,
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeAsyncSpecifier,
asyncSpecifier: asyncSpecifier,
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
unexpectedAfterThrowsSpecifier,
trailingTrivia: trailingTrivia
)
}
Expand Down Expand Up @@ -496,14 +522,20 @@ public extension TypeEffectSpecifiersSyntax {
@available(*, deprecated, message: "use throwsClause instead of throwsSpecifier")
init(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeAsyncSpecifier: UnexpectedNodesSyntax? = nil,
asyncSpecifier: TokenSyntax? = nil,
_ unexpectedBetweenAsyncSpecifierAndThrowsSpecifier: UnexpectedNodesSyntax? = nil,
throwsSpecifier: TokenSyntax? = nil,
_ unexpectedAfterThrowsSpecifier: UnexpectedNodesSyntax? = nil,
trailingTrivia: Trivia? = nil
) {
self.init(
leadingTrivia: leadingTrivia,
unexpectedBeforeAsyncSpecifier,
asyncSpecifier: asyncSpecifier,
unexpectedBetweenAsyncSpecifierAndThrowsSpecifier,
throwsClause: throwsSpecifier.map { ThrowsClauseSyntax(throwsSpecifier: $0) },
unexpectedAfterThrowsSpecifier,
trailingTrivia: trailingTrivia
)
}
Expand Down