Skip to content

Commit f9a97cf

Browse files
committed
fix
1 parent a61a1a7 commit f9a97cf

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,7 @@ extension Parser {
23772377

23782378
extension Parser {
23792379
mutating func parseDeclarationOrIfConfig() -> RawDeclSyntax {
2380-
if self.at(.poundIf) {
2380+
if self.at(.poundIf) && !self.withLookahead({ $0.consumeIfConfigOfAttributes() }) {
23812381
return RawDeclSyntax(
23822382
self.parsePoundIfDirective({
23832383
.decls($0.parseMemberDeclList(until: { $0.atEndOfIfConfigClauseBody() }))

Tests/SwiftParserTest/Parser+EntryTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ class EntryTests: ParserTestCase {
7070
)
7171
}
7272

73+
func testDeclSyntaxParseIfConfigAttr() throws {
74+
assertParse(
75+
"""
76+
#if FLAG
77+
@attr
78+
#endif
79+
func test() {}
80+
""",
81+
{ DeclSyntax.parse(from: &$0) },
82+
substructure: FunctionDeclSyntax(
83+
attributes: [
84+
.ifConfigDecl(IfConfigDeclSyntax(clauses: [
85+
IfConfigClauseSyntax(
86+
poundKeyword: .poundIfToken(),
87+
condition: DeclReferenceExprSyntax(baseName: .identifier("FLAG")),
88+
elements: .attributes([
89+
.attribute(AttributeSyntax(TypeSyntax(IdentifierTypeSyntax(name: .identifier("attr")))))
90+
]))
91+
]))
92+
],
93+
funcKeyword: .keyword(.func),
94+
name: .identifier("test"),
95+
signature: FunctionSignatureSyntax(
96+
parameterClause: FunctionParameterClauseSyntax(parameters: [])
97+
),
98+
body: CodeBlockSyntax(statements: [])
99+
)
100+
)
101+
}
102+
73103
func testRemainderUnexpected() throws {
74104
assertParse(
75105
"func test() {} 1️⃣other tokens",

0 commit comments

Comments
 (0)