-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Description
Description
Building any project using @Observable on Linux with Swift 6.2.3 fails with macro expansion errors.
Environment
- OS: Arch Linux (kernel 6.18.3-arch1-1)
- xtool: 1.16.1
- Swift: 6.2.3 (swift-6.2.3-RELEASE)
- iOS SDK: darwin (iOS 18.5 from Xcode)
Error
macro expansion @Observable:16:26: error: declaration name 'shouldNotifyObservers' is not covered by macro 'Observable'
The generated code shows mangled unique names:
private nonisolated func shouldNotifyObservers<$s6A_LIST22JourneysContentManager10ObservablefMm_6MemberfMu1_>(...)
Root Cause Analysis
The @Observable macro uses context.makeUniqueName("Member") for generic parameters. On Linux, these generate names starting with $ that look like Swift symbol manglings, which the compiler then rejects.
The macro declaration in Swift properly declares shouldNotifyObservers in its names: parameter:
@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation), named(shouldNotifyObservers))But the generated code uses unique mangled names that aren't being accepted.
Related Issues
- makeUniqueName() produces tokens that cannot be used as closure arguments swiftlang/swift-syntax#2256 (makeUniqueName produces $ prefixed names)
- Cross-compiling packages which contain macros doesn't work swiftlang/swift-package-manager#6950 (cross-compile macros)
Question
Is this a known limitation? Is there a workaround like using a different Swift version or toolchain configuration?
Metadata
Metadata
Assignees
Labels
No labels