Skip to content

[BUG] Example produces error "Conformance of 'Person' to protocol 'ResourceDefinitionProviding' crosses into main actor-isolated code and can cause data races" #19

Description

@kgutwin

Describe the bug

On Swift 6, in a macOS 26.2 project, the first example from the README produces the build error:

Conformance of 'Person' to protocol 'ResourceDefinitionProviding' crosses into main actor-isolated code and can cause data races

  • In expansion of macro 'ResourceWrapper' on struct 'Person' here
  • Conformance depends on main actor-isolated conformance of 'Person.Definition' to protocol 'ResourceDefinition'
  • Isolate this conformance to the main actor with '@ MainActor'

Checklist

  • I can reproduce this issue with a vanilla Swift project.
  • I can reproduce this issue using the main branch of this package.
  • This bug hasn't been addressed in an existing GitHub issue.

Steps to reproduce
Explanation of how to reproduce the incorrect behavior. This could include an attached project, a link to code, or a JSON:API document exhibiting the issue.

  1. Clone https://github.com/kgutwin/jsonapiTest
  2. Run xcodebuild -project jsonapiTest.xcodeproj -scheme jsonapiTest -sdk macosx build -skipMacroValidation (or just build within Xcode)

Observed

SwiftCompile normal arm64 /Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift (in target 'jsonapiTest' from project 'jsonapiTest')
    cd /Users/kgutwin/xcode/jsonapiTest
    
@__swiftmacro_11jsonapiTest6Person15ResourceWrapperfMe_.swift:1:27: error: conformance of 'Person' to protocol 'ResourceDefinitionProviding' crosses into main actor-isolated code and can cause data races
extension Person: JSONAPI.ResourceDefinitionProviding {
                          ^
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@__swiftmacro_11jsonapiTest6Person15ResourceWrapperfMe_.swift:1:27: note: isolate this conformance to the main actor with '@MainActor'
extension Person: JSONAPI.ResourceDefinitionProviding {
                          ^
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@__swiftmacro_11jsonapiTest6Person15ResourceWrapperfMe_.swift:1:1: note: conformance depends on main actor-isolated conformance of 'Person.Definition' to protocol 'ResourceDefinition'
extension Person: JSONAPI.ResourceDefinitionProviding {
^
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift:11:1: note: in expansion of macro 'ResourceWrapper' on struct 'Person' here
@ResourceWrapper(type: "people")
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SwiftDriverJobDiscovery normal arm64 Compiling GeneratedAssetSymbols.swift (in target 'jsonapiTest' from project 'jsonapiTest')

SwiftDriverJobDiscovery normal arm64 Compiling ContentView.swift (in target 'jsonapiTest' from project 'jsonapiTest')

SwiftCompile normal arm64 Compiling\ jsonapiTestApp.swift /Users/kgutwin/xcode/jsonapiTest/jsonapiTest/jsonapiTestApp.swift (in target 'jsonapiTest' from project 'jsonapiTest')

** BUILD FAILED **


The following build commands failed:
	SwiftCompile normal arm64 Compiling\ ApiModels.swift /Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift (in target 'jsonapiTest' from project 'jsonapiTest')
	SwiftCompile normal arm64 /Users/kgutwin/xcode/jsonapiTest/jsonapiTest/ApiModels.swift (in target 'jsonapiTest' from project 'jsonapiTest')
	Building project jsonapiTest with scheme jsonapiTest
(3 failures)

Expected behavior
The example code should compile as-is with no errors.

Version information

  • JSONAPI: 0.1.5
  • OS: macOS 26.5.1 (Tahoe)
  • Xcode: 26.2

Additional context
The reproduction repository uses the dependency from the fork https://github.com/bioteam/swift-jsonapi because my cursed Xcode configuration for some reason requires .git suffixes attached to the URLs defined in the Package.swift dependencies. I'm not expecting this has anything to do with the reported error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    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