Skip to content

Commit 54a3618

Browse files
committed
Don't treat a # as starting a declaration.
The recent change to rely on the general macro-expansion expression nodes for `#line` et al broke return statements because we were classifying the expression as a declaration.
1 parent 6cce791 commit 54a3618

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ extension Parser {
174174
return RawDeclSyntax(directive)
175175
case (.poundWarningKeyword, _)?, (.poundErrorKeyword, _)?:
176176
return self.parsePoundDiagnosticDeclaration()
177-
case (.pound, _)?:
178-
return RawDeclSyntax(self.parseMacroExpansionDeclaration())
179177
case nil:
180178
break
181179
}
182180

181+
if (self.at(.pound)) {
182+
// FIXME: If we can have attributes for macro expansions, handle this
183+
// via DeclarationStart.
184+
return RawDeclSyntax(self.parseMacroExpansionDeclaration())
185+
}
186+
183187
let attrs = DeclAttributes(
184188
attributes: self.parseAttributeList(),
185189
modifiers: self.parseModifierList())

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,12 @@ enum PoundDeclarationStart: RawTokenKindSubset {
574574
case poundIfKeyword
575575
case poundWarningKeyword
576576
case poundErrorKeyword
577-
case pound
578577

579578
init?(lexeme: Lexer.Lexeme) {
580579
switch lexeme.tokenKind {
581580
case .poundIfKeyword: self = .poundIfKeyword
582581
case .poundWarningKeyword: self = .poundWarningKeyword
583582
case .poundErrorKeyword: self = .poundErrorKeyword
584-
case .pound: self = .pound
585583
default: return nil
586584
}
587585
}
@@ -591,7 +589,6 @@ enum PoundDeclarationStart: RawTokenKindSubset {
591589
case .poundIfKeyword: return .poundIfKeyword
592590
case .poundWarningKeyword: return .poundWarningKeyword
593591
case .poundErrorKeyword: return .poundErrorKeyword
594-
case .pound: return .pound
595592
}
596593
}
597594
}

Tests/SwiftParserTest/Expressions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ final class ExpressionTests: XCTestCase {
238238
__COLUMN__
239239
__FUNCTION__
240240
__DSO_HANDLE__
241+
242+
func f() {
243+
return #function
244+
}
241245
"""
242246
)
243247
}

0 commit comments

Comments
 (0)