Skip to content
Open
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
11 changes: 0 additions & 11 deletions Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ private func expandPeerMacroMember(
in context: some MacroExpansionContext,
indentationWidth: Trivia
) throws -> MemberBlockItemListSyntax? {
if let variable = attachedTo.as(VariableDeclSyntax.self), variable.bindings.count > 1 {
throw MacroApplicationError.peerMacroOnVariableWithMultipleBindings
}

guard
let expanded = expandAttachedMacro(
definition: definition,
Expand Down Expand Up @@ -278,10 +274,6 @@ private func expandPeerMacroCodeItem(
in context: some MacroExpansionContext,
indentationWidth: Trivia
) throws -> CodeBlockItemListSyntax? {
if let variable = attachedTo.as(VariableDeclSyntax.self), variable.bindings.count > 1 {
throw MacroApplicationError.peerMacroOnVariableWithMultipleBindings
}

guard
let expanded = expandAttachedMacro(
definition: definition,
Expand Down Expand Up @@ -622,7 +614,6 @@ let diagnosticDomain: String = "SwiftSyntaxMacroExpansion"

private enum MacroApplicationError: DiagnosticMessage, Error {
case accessorMacroOnVariableWithMultipleBindings
case peerMacroOnVariableWithMultipleBindings
case malformedAccessor

var diagnosticID: MessageID {
Expand All @@ -635,8 +626,6 @@ private enum MacroApplicationError: DiagnosticMessage, Error {
switch self {
case .accessorMacroOnVariableWithMultipleBindings:
return "accessor macro can only be applied to a single variable"
case .peerMacroOnVariableWithMultipleBindings:
return "peer macro can only be applied to a single variable"
case .malformedAccessor:
return """
macro returned a malformed accessor. Accessors should start with an introducer like 'get' or 'set'.
Expand Down
37 changes: 31 additions & 6 deletions Tests/SwiftSyntaxMacroExpansionTest/PeerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ final class PeerMacroTests: XCTestCase {
""",
expandedSource: """
let a = 17, b = 12

var baz: Int = 0
""",
diagnostics: [
DiagnosticSpec(message: "peer macro can only be applied to a single variable", line: 1, column: 1)
],
macros: ["Test": TestMacro.self]
)

Expand All @@ -188,11 +187,37 @@ final class PeerMacroTests: XCTestCase {
expandedSource: """
struct Foo {
let a = 17, b = 12

var baz: Int = 0
}
""",
macros: ["Test": TestMacro.self]
)
}

func testPeerMacroReturningNoPeersOnVariableWithMultipleBindings() {
struct TestMacro: PeerMacro {
static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
return []
}
}

assertMacroExpansion(
"""
struct Foo {
@Test
var a: Int, b: Int
}
""",
expandedSource: """
struct Foo {
var a: Int, b: Int
}
""",
diagnostics: [
DiagnosticSpec(message: "peer macro can only be applied to a single variable", line: 2, column: 3)
],
macros: ["Test": TestMacro.self]
)
}
Expand Down