From 445ef28d7569b00e703be079fc0909968dc03f59 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 17 Oct 2025 10:59:19 +0200 Subject: [PATCH] Minor cleanup from `if` to `guard` statement I think the guard is a lot easier to read here, noticed while reviewing https://github.com/swiftlang/swift-syntax/pull/3171. --- Sources/SwiftParser/Lookahead.swift | 2 +- Tests/SwiftParserTest/DeclarationTests.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftParser/Lookahead.swift b/Sources/SwiftParser/Lookahead.swift index 90748e2cd38..ff3b1a66b2f 100644 --- a/Sources/SwiftParser/Lookahead.swift +++ b/Sources/SwiftParser/Lookahead.swift @@ -266,7 +266,7 @@ extension Parser.Lookahead { } // If we don't have attributes, then it cannot be an accessor block. - if nextToken.rawTokenKind != .atSign { + guard self.peek(isAt: .atSign) else { return false } diff --git a/Tests/SwiftParserTest/DeclarationTests.swift b/Tests/SwiftParserTest/DeclarationTests.swift index 5818b008d85..44c95f9ed38 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -3831,4 +3831,16 @@ final class UsingDeclarationTests: ParserTestCase { ) ) } + + func testAccessorBlockAfterPatternBindingDeclWithAttribute() { + assertParse( + """ + var x: Int = foo() + { + @available(*, deprecated) + didSet {} + } + """ + ) + } }