Skip to content

Commit 90184c3

Browse files
committed
Remove parsing of "value-like" macro declarations
This `macro m: T` macro syntax was present in early macro proposals, but has not been used in a while and isn't in the accepted form. Remove it.
1 parent 7200b19 commit 90184c3

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,15 +2164,7 @@ extension Parser {
21642164
}
21652165

21662166
// Macro signature, which is either value-like or function-like.
2167-
let signature: RawMacroDeclSyntax.Signature
2168-
if let colon = self.consume(if: .colon) {
2169-
let type = self.parseType()
2170-
signature = .valueLike(
2171-
RawTypeAnnotationSyntax(colon: colon, type: type, arena: self.arena)
2172-
)
2173-
} else {
2174-
signature = .functionLike(self.parseFunctionSignature())
2175-
}
2167+
let signature = self.parseFunctionSignature()
21762168

21772169
// Initializer, if any.
21782170
let definition: RawInitializerClauseSyntax?

Sources/SwiftSyntaxMacros/MacroReplacement.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ fileprivate class ParameterReplacementVisitor: SyntaxAnyVisitor {
114114
// of a macro.
115115
override func visit(_ node: IdentifierExprSyntax) -> SyntaxVisitorContinueKind {
116116
let identifier = node.identifier
117-
118-
// FIXME: This will go away.
119-
guard case let .functionLike(signature) = macro.signature else {
120-
return .visitChildren
121-
}
117+
let signature = macro.signature
122118

123119
let matchedParameter = signature.input.parameterList.enumerated().first { (index, parameter) in
124120
if identifier.text == "_" {

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,12 +1334,18 @@ final class DeclarationTests: XCTestCase {
13341334
func testMacroDecl() {
13351335
AssertParse(
13361336
"""
1337-
macro m1: Int = A.M1
1337+
macro m11️⃣: Int = A.M1
13381338
macro m2(_: Int) = A.M2
13391339
macro m3(a b: Int) -> Int = A.M3
1340-
macro m4<T>: T = A.M4 where T.Assoc: P
1340+
macro m4<T>2️⃣: T = A.M4 where T.Assoc: P
13411341
macro m5<T: P>(_: T)
1342-
"""
1342+
""",
1343+
diagnostics: [
1344+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected parameter clause in function signature"),
1345+
DiagnosticSpec(locationMarker: "1️⃣", message: "unexpected code ': Int = A.M1' before macro"),
1346+
DiagnosticSpec(locationMarker: "2️⃣", message: "expected parameter clause in function signature"),
1347+
DiagnosticSpec(locationMarker: "2️⃣", message: "unexpected code ': T = A.M4 where T.Assoc: P' before macro")
1348+
]
13431349
)
13441350

13451351
AssertParse(

0 commit comments

Comments
 (0)