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 @@ -1839,7 +1839,7 @@ final class StatementExpressionTests: XCTestCase {
1839
1839
]
1840
1840
)
1841
1841
}
1842
-
1842
+
1843
1843
func testConsecutiveStatements2( ) {
1844
1844
assertParse (
1845
1845
" switch x {case y: a1️⃣ b2️⃣ c} " ,
@@ -1849,7 +1849,7 @@ final class StatementExpressionTests: XCTestCase {
1849
1849
]
1850
1850
)
1851
1851
}
1852
-
1852
+
1853
1853
func testConsecutiveStatements3( ) {
1854
1854
assertParse (
1855
1855
"""
@@ -1861,7 +1861,7 @@ final class StatementExpressionTests: XCTestCase {
1861
1861
]
1862
1862
)
1863
1863
}
1864
-
1864
+
1865
1865
func testConsecutiveStatements4( ) {
1866
1866
assertParse (
1867
1867
"""
@@ -1874,6 +1874,43 @@ final class StatementExpressionTests: XCTestCase {
1874
1874
)
1875
1875
}
1876
1876
1877
+ func testInitCallInPoundIf( ) {
1878
+ // Make sure we parse 'init()' as an expr, not a decl.
1879
+ assertParse (
1880
+ """
1881
+ class C {
1882
+ init() {
1883
+ #if true
1884
+ init()
1885
+ #endif
1886
+ }
1887
+ }
1888
+ """ ,
1889
+ substructure: Syntax (
1890
+ FunctionCallExprSyntax (
1891
+ calledExpression: IdentifierExprSyntax ( identifier: . keyword( . init( " init " ) !) ) ,
1892
+ leftParen: . leftParenToken( ) ,
1893
+ argumentList: TupleExprElementListSyntax ( [ ] ) ,
1894
+ rightParen: . rightParenToken( )
1895
+ )
1896
+ )
1897
+ )
1898
+ }
1899
+
1900
+ func testUnexpectedCloseBraceInPoundIf( ) {
1901
+ assertParse (
1902
+ """
1903
+ #if true
1904
+ 1️⃣}
1905
+ class C {}
1906
+ #endif
1907
+ """ ,
1908
+ diagnostics: [
1909
+ DiagnosticSpec ( message: " unexpected brace before class " )
1910
+ ]
1911
+ )
1912
+ }
1913
+
1877
1914
func testStringLiteralAfterKeyPath( ) {
1878
1915
assertParse (
1879
1916
#"""
You can’t perform that action at this time.
0 commit comments