File tree Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ extension Parser {
229
229
// If config of attributes is parsed as part of declaration parsing as it
230
230
// doesn't constitute its own code block item.
231
231
let directive = self . parsePoundIfDirective { ( parser, _) in
232
- parser. parseCodeBlockItem ( isAtTopLevel: false , allowInitDecl: true )
232
+ parser. parseCodeBlockItem ( isAtTopLevel: isAtTopLevel , allowInitDecl: allowInitDecl )
233
233
} addSemicolonIfNeeded: { lastElement, newItemAtStartOfLine, parser in
234
234
if lastElement. semicolon == nil && !newItemAtStartOfLine {
235
235
return RawCodeBlockItemSyntax (
Original file line number Diff line number Diff line change @@ -1820,7 +1820,7 @@ final class StatementExpressionTests: XCTestCase {
1820
1820
]
1821
1821
)
1822
1822
}
1823
-
1823
+
1824
1824
func testConsecutiveStatements2( ) {
1825
1825
assertParse (
1826
1826
" switch x {case y: a1️⃣ b2️⃣ c} " ,
@@ -1830,7 +1830,7 @@ final class StatementExpressionTests: XCTestCase {
1830
1830
]
1831
1831
)
1832
1832
}
1833
-
1833
+
1834
1834
func testConsecutiveStatements3( ) {
1835
1835
assertParse (
1836
1836
"""
@@ -1842,7 +1842,7 @@ final class StatementExpressionTests: XCTestCase {
1842
1842
]
1843
1843
)
1844
1844
}
1845
-
1845
+
1846
1846
func testConsecutiveStatements4( ) {
1847
1847
assertParse (
1848
1848
"""
@@ -1855,6 +1855,43 @@ final class StatementExpressionTests: XCTestCase {
1855
1855
)
1856
1856
}
1857
1857
1858
+ func testInitCallInPoundIf( ) {
1859
+ // Make sure we parse 'init()' as an expr, not a decl.
1860
+ assertParse (
1861
+ """
1862
+ class C {
1863
+ init() {
1864
+ #if true
1865
+ init()
1866
+ #endif
1867
+ }
1868
+ }
1869
+ """ ,
1870
+ substructure: Syntax (
1871
+ FunctionCallExprSyntax (
1872
+ calledExpression: IdentifierExprSyntax ( identifier: . keyword( . init( " init " ) !) ) ,
1873
+ leftParen: . leftParenToken( ) ,
1874
+ argumentList: TupleExprElementListSyntax ( [ ] ) ,
1875
+ rightParen: . rightParenToken( )
1876
+ )
1877
+ )
1878
+ )
1879
+ }
1880
+
1881
+ func testUnexpectedCloseBraceInPoundIf( ) {
1882
+ assertParse (
1883
+ """
1884
+ #if true
1885
+ 1️⃣}
1886
+ class C {}
1887
+ #endif
1888
+ """ ,
1889
+ diagnostics: [
1890
+ DiagnosticSpec ( message: " unexpected brace before class " )
1891
+ ]
1892
+ )
1893
+ }
1894
+
1858
1895
func testStringLiteralAfterKeyPath( ) {
1859
1896
assertParse (
1860
1897
#"""
You can’t perform that action at this time.
0 commit comments