From a4ae2ef91050f70f0f0a541fc0a7a61d16a0bb10 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 4c16f78b8b9..5a6157903ab 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 5abae62a131..2034223ac5a 100644 --- a/Tests/SwiftParserTest/DeclarationTests.swift +++ b/Tests/SwiftParserTest/DeclarationTests.swift @@ -3768,4 +3768,16 @@ final class UsingDeclarationTests: ParserTestCase { """ ) } + + func testAccessorBlockAfterPatternBindingDeclWithAttribute() { + assertParse( + """ + var x: Int = 2 + { + @something + didSet {} + } + """ + ) + } }