Skip to content

Don't treat a # as starting a declaration. #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ extension Parser {
return RawDeclSyntax(directive)
case (.poundWarningKeyword, _)?, (.poundErrorKeyword, _)?:
return self.parsePoundDiagnosticDeclaration()
case (.pound, _)?:
return RawDeclSyntax(self.parseMacroExpansionDeclaration())
case nil:
break
}

if (self.at(.pound)) {
// FIXME: If we can have attributes for macro expansions, handle this
// via DeclarationStart.
return RawDeclSyntax(self.parseMacroExpansionDeclaration())
}

let attrs = DeclAttributes(
attributes: self.parseAttributeList(),
modifiers: self.parseModifierList())
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftParser/RawTokenKindSubset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,12 @@ enum PoundDeclarationStart: RawTokenKindSubset {
case poundIfKeyword
case poundWarningKeyword
case poundErrorKeyword
case pound

init?(lexeme: Lexer.Lexeme) {
switch lexeme.tokenKind {
case .poundIfKeyword: self = .poundIfKeyword
case .poundWarningKeyword: self = .poundWarningKeyword
case .poundErrorKeyword: self = .poundErrorKeyword
case .pound: self = .pound
default: return nil
}
}
Expand All @@ -591,7 +589,6 @@ enum PoundDeclarationStart: RawTokenKindSubset {
case .poundIfKeyword: return .poundIfKeyword
case .poundWarningKeyword: return .poundWarningKeyword
case .poundErrorKeyword: return .poundErrorKeyword
case .pound: return .pound
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/SwiftParserTest/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ final class ExpressionTests: XCTestCase {
__COLUMN__
__FUNCTION__
__DSO_HANDLE__

func f() {
return #function
}
"""
)
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/SwiftParserTest/translated/RawStringErrorsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ final class RawStringErrorsTests: XCTestCase {
// TODO: Old parser expected error on line 1: consecutive statements on a line must be separated by ';'
// TODO: Old parser expected error on line 1: expected expression
DiagnosticSpec(locationMarker: "1️⃣", message: "consecutive statements on a line must be separated by ';'"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "4️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected identifier in pound literal expression"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected identifier in pound literal expression"),
DiagnosticSpec(locationMarker: "4️⃣", message: "expected identifier in pound literal expression"),
]
)
}
Expand All @@ -70,9 +70,9 @@ final class RawStringErrorsTests: XCTestCase {
// TODO: Old parser expected error on line 1: consecutive statements on a line must be separated by ';'
// TODO: Old parser expected error on line 1: expected expression
DiagnosticSpec(locationMarker: "1️⃣", message: "consecutive statements on a line must be separated by ';'"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "4️⃣", message: "expected identifier in pound literal declaration"),
DiagnosticSpec(locationMarker: "2️⃣", message: "expected identifier in pound literal expression"),
DiagnosticSpec(locationMarker: "3️⃣", message: "expected identifier in pound literal expression"),
DiagnosticSpec(locationMarker: "4️⃣", message: "expected identifier in pound literal expression"),
]
)
}
Expand Down
16 changes: 8 additions & 8 deletions Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ final class MacroSystemTests: XCTestCase {
struct X {
var computed: String {
get {
(#function)
#function
}
}

init(from: String) {
(#function)
#function
}

subscript(a: Int) -> String {
(#function)
#function
}

subscript(a a: Int) -> String {
(#function)
#function
}
}

Expand All @@ -81,20 +81,20 @@ final class MacroSystemTests: XCTestCase {
struct X {
var computed: String {
get {
("computed")
"computed"
}
}

init(from: String) {
("init(from:)")
"init(from:)"
}

subscript(a: Int) -> String {
("subscript(_:)")
"subscript(_:)"
}

subscript(a a: Int) -> String {
("subscript(a:)")
"subscript(a:)"
}
}

Expand Down