public struct AddCaseMacro: PeerMacro {
public static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
["case addedCase"]
}
}
Apply the macro to a declaration inside of an enum, alongside another case:
enum Foo {
case foo
@AddCase
enum Bar {}
}
Switch over an enum value:
func fooBar(_ foo: Foo) {
switch foo {
case .foo:
break
case .addedCase:
break
}
}
Expected behavior
Code works normally, as if a case was added manually and not through the macro.
Actual behavior
Compilation crashes. Also switch autocomplete doesn't insert a case added by macro automatically, xcode doesn't color case .addedCase the same color as case .foo. If case foo is not added, Foo enum is considered unpopulated.
Swift compiler version info swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.2 clang-1500.0.40.1) Target: arm64-apple-macosx13.0
Xcode version info Xcode 15.0 Build version 15A5229h
Deployment target: iOS 13
swift-syntax version 509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b
Description
Compiler crashes when trying to switch over an
enum
value with a case, added by a macro.Steps to reproduce
Minimal reproducing project: https://github.com/romikabi/MacroBug
enum
case:Apply the macro to a declaration inside of an
enum
, alongside another case:enum
value:Expected behavior
Code works normally, as if a case was added manually and not through the macro.
Actual behavior Compilation crashes. Also
switch
autocomplete doesn't insert a case added by macro automatically, xcode doesn't colorcase .addedCase
the same color ascase .foo
. Ifcase foo
is not added,Foo
enum is considered unpopulated.Stack dump
``` 0. Program arguments: /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/romikabi/Projects/MacroBug/Sources/MacroBugClient/main.swift -emit-dependencies-path /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.d -emit-const-values-path /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.swiftconstvalues -emit-reference-dependencies-path /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.swiftdeps -serialize-diagnostics-path /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.dia -target arm64-apple-macos10.15 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -I /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Products/Debug -I /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Products/Debug/PackageFrameworks -F /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Products/Debug -F /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/romikabi/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -load-plugin-executable /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Products/Debug/MacroBugMacros#MacroBugMacros -package-name macrobug -const-gather-protocols-file /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/MacroBugClient_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/romikabi/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/romikabi/Projects/MacroBug -resource-dir /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -ivfsstatcache -Xcc /Users/romikabi/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx14.0-23A5312c-430ebd289dba5af249207038329132b1.sdkstatcache -Xcc -I/Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Products/Debug/include -Xcc -I/Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/DerivedSources-normal/arm64 -Xcc -I/Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/DerivedSources/arm64 -Xcc -I/Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name MacroBugClient -frontend-parseable-output -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0 -external-plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Build/Intermediates.noindex/MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.o -index-unit-output-path /MacroBug.build/Debug/MacroBugClient.build/Objects-normal/arm64/main.o -index-store-path /Users/romikabi/Library/Developer/Xcode/DerivedData/MacroBug-bpweuzevkghtofgkvsqckothtidv/Index.noindex/DataStore -index-system-modules 1. Apple Swift version 5.9 (swiftlang-5.9.0.128.2 clang-1500.0.40.1) 2. Compiling with the current language version 3. While evaluating request IRGenRequest(IR Generation for file "/Users/romikabi/Projects/MacroBug/Sources/MacroBugClient/main.swift") 4. While emitting IR SIL function "@$s14MacroBugClient6fooBaryyAA3FooOF". for 'fooBar(_:)' (at /Users/romikabi/Projects/MacroBug/Sources/MacroBugClient/main.swift:14:1) Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 swift-frontend 0x00000001030c5d04 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56 1 swift-frontend 0x000000010106c4d4 llvm::sys::RunSignalHandlers() + 112 2 swift-frontend 0x00000001030c6500 SignalHandler(int) + 352 3 libsystem_platform.dylib 0x00000001942b6a24 _sigtramp + 56 4 libsystem_platform.dylib 0xffff800101c47360 _sigtramp + 18446603333764974964 5 swift-frontend 0x000000010540f734 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 63344 6 swift-frontend 0x00000001053d4234 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 11680 7 swift-frontend 0x0000000102fac114 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vectorEnvironment
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.2 clang-1500.0.40.1) Target: arm64-apple-macosx13.0
Xcode 15.0 Build version 15A5229h
iOS 13
509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b