Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with macro and any AsyncSequence #312

Closed
3 tasks done
brzzdev opened this issue Nov 18, 2024 · 1 comment
Closed
3 tasks done

Issue with macro and any AsyncSequence #312

brzzdev opened this issue Nov 18, 2024 · 1 comment
Labels
apple bug Something isn't working due to a bug on Apple's platforms.

Comments

@brzzdev
Copy link

brzzdev commented Nov 18, 2024

Description

With eraseToStream() now being deprecated, I was switching my dependencies over to any AsyncSequence<Element, Failure and found that using .never no longer works (expected), and that switching to AsyncStream.never causes a compiler error.
It appears to be some interaction between the macro and unimplemented, as:
Without the macro

struct Example {
  var exampleSequence: () -> any AsyncSequence<Int, Never> = {
    unimplemented(
      "",
      placeholder: AsyncStream.never
    )
  }
}

and without unimplemented

@DependencyClient
struct Example {
  var exampleSequence: () -> any AsyncSequence<Int, Never> = {
    AsyncStream.never
  }
}

both work
but

@DependencyClient
struct Example {
  var exampleSequence: () -> any AsyncSequence<Int, Never> = {
    unimplemented(
      "",
      placeholder: AsyncStream.never
    )
  }
}

causes a compiler error.

Also worth noting that explicitly casting AsyncStream.never as any AsyncSequence<Int, Never> builds, but is obviously unergonomic to cast like that in every unimplemented method

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Above example compiles

Dependencies version information

1.5.2

Destination operating system

macOS 15

Xcode version information

16.1

Swift Compiler version information

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0
@brzzdev brzzdev added the bug Something isn't working label Nov 18, 2024
@stephencelis
Copy link
Member

@brzzdev Thanks for the report! I just looked into it, and it looks like it's a Swift bug.

You can repro using just the @DependencyEndpoint macro:

struct Example {
  @DependencyEndpoint
  var exampleSequence: () -> any AsyncSequence<Int, Never> = {
    unimplemented(
      "",
      placeholder: AsyncStream.never
    )
  }
}

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.

I'd recommend filing a bug with Swift if you can!

While we're open to local workarounds to fix the issue, we probably won't have time to investigate ourselves. In the meantime I'd probably recommend not using unimplemented here and instead reproduce what it does, which is probably shorter and more understandable:

struct Example {
  @DependencyEndpoint
  var exampleSequence: () -> any AsyncSequence<Int, Never> = {
    reportIssue()
    return AsyncStream.never
  }
}

@stephencelis stephencelis added apple bug Something isn't working due to a bug on Apple's platforms. and removed bug Something isn't working labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple bug Something isn't working due to a bug on Apple's platforms.
Projects
None yet
Development

No branches or pull requests

2 participants