Sendable error when creating archive build and Swift 6

When creating an archive build using Xcode 16 (beta) and Swift 6 enabled, I'm seeing a build error that doesn't exist when creating a debug build (build and run or unit tests) that I'm not sure about the best approach for fixing.

The error I'm seeing is related to the swift-dependencies SPM package from PointFree and a GitHub issue has been raised here to try and look at a solution. Unfortunately my understanding is a bit limited as to what the best approach to take here would be.

The error:

swift-dependencies/Sources/Dependencies/WithDependencies.swift:491:17 Non-sendable type 'R' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary

The code snipped causing the issue:

#if swift(>=6)
  @_transparent
  private func isSetting<R>(
    _ value: Bool,
    isolation: isolated (any Actor)? = #isolation,
    operation: () async throws -> R
  ) async rethrows -> R {
    #if DEBUG
      try await DependencyValues.$isSetting.withValue(value, operation: operation)
    #else
      try await operation()
    #endif
  }
#else
  @_transparent
  private func isSetting<R>(
    _ value: Bool,
    operation: () async throws -> R
  ) async rethrows -> R {
    #if DEBUG
      try await DependencyValues.$isSetting.withValue(value, operation: operation)
    #else
      try await operation()
    #endif
  }
#endif

The Fix-it of applying Sendable to the generic type R is one option, though with it only being an error when doing release / archive builds I'm a bit confused as to whether it's a good approach.

Are there any other solutions that could be looked at?

Thanks,
Amy.

You can add sending instead of requiring Sendable conformance. If R happen to be Sendable you are good, since it can be though of as a subset of sending types.

Is sending being inferred here in the debug builds but somehow it not in release? Is this a Swift bug that should be reported?

1 Like

I suppose it is being inferred from DependencyValues (quick look into code suggests that withValue has Sendable requirement on a type). In release mode it has nothing to rely on, so behaviour seems to be correct for me.


Oh, I just now realised that snipped in post is from the library code!

1 Like

Clear as day now, thanks!

1 Like