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 {
23772377
23782378extension 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 ( ) } ) )
Original file line number Diff line number Diff 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 " ,
You can’t perform that action at this time.
0 commit comments