swiftlang/swift-syntax

Expand Macro on ExpressionMacro crashes Xcode 15.2 with EXC_BAD_INSTRUCTION _assertionFailure

taher-mosbah opened this issue · 1 comments

Description

Selecting Expand Macro on contextual menu on an ExpressionMacro crashes Xcode, Macro is working as expected though.

Environment:

  • Xcode 15.2
  • tested with stock toolchain and swift-5.10-DEVELOPMENT-SNAPSHOT-2024-01-18-a-osx
  • swift-syntax version 509.1.1

Steps to Reproduce

Macro code:

public struct TestMacro: ExpressionMacro {
    public static func expansion(
        of node: some FreestandingMacroExpansionSyntax,
        in context: some MacroExpansionContext
    ) throws -> ExprSyntax {
        let arguments = node.argumentList.map { "\($0.expression)" }
        return "Test(a: \(raw: arguments[0]), b: \(raw: arguments[1]),c: \(raw: arguments[2]), d: \(raw: arguments[3]), e: \(raw: arguments[4]))"
    }
}

@main
struct TestPlugin: CompilerPlugin {
    let providingMacros: [Macro.Type] = [
        TestMacro.self
    ]
}
  • Embed macro as SPM
  • Call macro from app
  • Right click macro call -> Expand Macro
  • Xcode crash on: 0 libswiftCore.dylib 0x7ff813cdf232 _assertionFailure(_:_:file:line:flags:) + 354
  • Crash is reproducible every time

Crash report:
Xcode-2024-01-23-101955.ips.zip

Since this is an Xcode crash and not a crash of open source components of Swift, could you file a feedback for this at http://feedback.apple.com/?