Skip to content

@Observable macro fails on Linux: 'shouldNotifyObservers' not covered by macro (Swift 6.2.3) #197

@guitaripod

Description

@guitaripod

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

Question

Is this a known limitation? Is there a workaround like using a different Swift version or toolchain configuration?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions