File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -2377,7 +2377,7 @@ extension Parser {
2377
2377
2378
2378
extension Parser {
2379
2379
mutating func parseDeclarationOrIfConfig( ) -> RawDeclSyntax {
2380
- if self . at ( . poundIf) {
2380
+ if self . at ( . poundIf) && ! self . withLookahead ( { $0 . consumeIfConfigOfAttributes ( ) } ) {
2381
2381
return RawDeclSyntax (
2382
2382
self . parsePoundIfDirective ( {
2383
2383
. decls( $0. parseMemberDeclList ( until: { $0. atEndOfIfConfigClauseBody ( ) } ) )
Original file line number Diff line number Diff line change @@ -70,6 +70,36 @@ class EntryTests: ParserTestCase {
70
70
)
71
71
}
72
72
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
+
73
103
func testRemainderUnexpected( ) throws {
74
104
assertParse (
75
105
" func test() {} 1️⃣other tokens " ,
You can’t perform that action at this time.
0 commit comments