Skip to content

Detect circular macro expansion in MacroSystem #2018

Closed
@ahoppen

Description

@ahoppen

The following recursive expansion of a macro causes an infinite loop in MacroSystem, which is used by assertMacroExpansion. The compiler diagnoses the circular evaluation of the macro. MacroSystem should do the same.

struct InfiniteRecursionMacro: ExpressionMacro {
  static func expansion(of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext) throws -> ExprSyntax {
    return "#infiniteRecursion"
  }
}

final class MacroSystemTests: XCTestCase {
  func testInfiniteRecursion() {
    assertMacroExpansion("#infiniteRecursion", expandedSource: "", macros: ["infiniteRecursion": InfiniteRecursionMacro.self])
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    MacrosIssues in the SwiftSyntaxMacro… modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions