apple / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expand Macro on ExpressionMacro crashes Xcode 15.2 with EXC_BAD_INSTRUCTION _assertionFailure

taher-mosbah opened this issue · 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/?