Skip to content

Resolves issue with endpoints not reporting errors when there's a custom closure #355

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

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro {
}

return [
"""
@storageRestrictions(initializes: _\(raw: identifier))
init(initialValue) {
_\(raw: identifier) = initialValue
}
""",
"""
get {
_\(raw: identifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,6 @@ final class DependencyClientMacroTests: BaseTestCase {
struct Client {
@available(iOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(macOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(tvOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(watchOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.")
var fetch: (_ id: Int) throws -> String {
@storageRestrictions(initializes: _fetch)
init(initialValue) {
_fetch = initialValue
}
get {
_fetch
}
Expand Down Expand Up @@ -864,10 +860,6 @@ final class DependencyClientMacroTests: BaseTestCase {
struct Client {
@available(iOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(macOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(tvOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.") @available(watchOS, deprecated: 9999, message: "This property has a method equivalent that is preferred for autocomplete via this deprecation. It is perfectly fine to use for overriding and accessing via '@Dependency'.")
var fetch: (_ id: Int) throws -> String {
@storageRestrictions(initializes: _fetch)
init(initialValue) {
_fetch = initialValue
}
get {
_fetch
}
Expand Down Expand Up @@ -910,10 +902,6 @@ final class DependencyClientMacroTests: BaseTestCase {
#"""
struct Client {
var fetch: (Int) throws -> String {
@storageRestrictions(initializes: _fetch)
init(initialValue) {
_fetch = initialValue
}
get {
_fetch
}
Expand Down
15 changes: 11 additions & 4 deletions Tests/DependenciesMacrosPluginTests/DependencyClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ final class DependencyClientTests: BaseTestCase {
}
}

func testSwiftBug() {
func testUnimplementedWithNonThrowingEndpoint() {
let client = ClientWithNonThrowingEndpoint()

// NB: This should cause a test failure but currently does not due to a Swift compiler bug:
// https://github.com/apple/swift/issues/71070
XCTAssertEqual(client.fetch(), 42)
XCTExpectFailure {
XCTAssertEqual(client.fetch(), 42)
} issueMatcher: {
$0.compactDescription == """
failed - Unimplemented: \'ClientWithNonThrowingEndpoint.fetch\'
"""
}

XCTExpectFailure {
XCTAssertEqual(client.fetchWithUnimplemented(), 42)
} issueMatcher: {
$0.compactDescription == """
failed - Unimplemented: \'ClientWithNonThrowingEndpoint.fetchWithUnimplemented\'
""" ||
$0.compactDescription == """
failed - Unimplemented …

Expand Down
109 changes: 0 additions & 109 deletions Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -56,10 +52,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Bool {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -110,10 +102,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Bool {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -164,10 +152,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: (Int, Bool, String) -> Bool {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -197,10 +181,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () throws -> Bool {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -230,10 +210,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
public struct ApiClient {
public var apiRequest: @Sendable (ServerRoute.Api.Route) async throws -> (Data, URLResponse) {
@storageRestrictions(initializes: _apiRequest)
init(initialValue) {
_apiRequest = initialValue
}
get {
_apiRequest
}
Expand Down Expand Up @@ -263,10 +239,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> () {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -295,10 +267,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Int? {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -328,10 +296,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Optional<Int> {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -361,10 +325,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: @Sendable (Int) -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -393,10 +353,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
public struct Client {
public var endpoint: @Sendable (String, _ id: Int, _ progress: Float) async -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -430,10 +386,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
public struct Client {
public var endpoint: @MainActor @Sendable (_ id: Int) async -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -467,10 +419,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
public struct Client {
public var endpoint: @Sendable (_ id: Int) async -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -504,10 +452,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: (_ id: Int) -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -540,10 +484,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -596,10 +536,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: (_ id: Int) -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -649,10 +585,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
} expansion: {
#"""
var `return`: () throws -> Int {
@storageRestrictions(initializes: _return)
init(initialValue) {
_return = initialValue
}
get {
_return
}
Expand All @@ -678,10 +610,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
} expansion: {
#"""
var `return`: (_ id: Int) throws -> Int {
@storageRestrictions(initializes: _return)
init(initialValue) {
_return = initialValue
}
get {
_return
}
Expand Down Expand Up @@ -737,10 +665,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Blah {
public var doAThing: (_ value: Int) -> String {
@storageRestrictions(initializes: _doAThing)
init(initialValue) {
_doAThing = initialValue
}
get {
_doAThing
}
Expand Down Expand Up @@ -776,10 +700,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Blah {
public var doAThing: (_ a: inout Int, _ b: Int, _ c: inout Bool) -> String {
@storageRestrictions(initializes: _doAThing)
init(initialValue) {
_doAThing = initialValue
}
get {
_doAThing
}
Expand Down Expand Up @@ -813,10 +733,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Foo {
var bar: (_ a: @autoclosure () -> Int, _ b: () -> Int, _ c: @autoclosure () -> Int) -> Void {
@storageRestrictions(initializes: _bar)
init(initialValue) {
_bar = initialValue
}
get {
_bar
}
Expand Down Expand Up @@ -891,10 +807,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Blah {
public var foo: () -> Void {
@storageRestrictions(initializes: _foo)
init(initialValue) {
_foo = initialValue
}
get {
_foo
}
Expand All @@ -910,10 +822,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
}()
}
public var bar: () -> String {
@storageRestrictions(initializes: _bar)
init(initialValue) {
_bar = initialValue
}
get {
_bar
}
Expand Down Expand Up @@ -952,11 +860,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
willSet {
print("!")
}
@storageRestrictions(initializes: _foo)
init(initialValue) {
_foo = initialValue
}

get {
_foo
}
Expand Down Expand Up @@ -991,10 +894,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
package struct Client {
package var endpoint: () -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -1023,10 +922,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
package struct Client {
package var endpoint: (_ id: Int) -> Void {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down Expand Up @@ -1059,10 +954,6 @@ final class DependencyEndpointMacroTests: BaseTestCase {
#"""
struct Client {
var endpoint: () -> Void // This is a comment {
@storageRestrictions(initializes: _endpoint)
init(initialValue) {
_endpoint = initialValue
}
get {
_endpoint
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
var endpoint: () -> Int = { 42 }
}
let client = Client()
// NB: This invocation of 'endpoint' *should* fail, but it does not due to a bug in the
// Swift compiler: https://github.com/apple/swift/issues/71070
let output = client.endpoint()
XCTAssert(output == 42)
XCTExpectFailure {
_ = client.endpoint()
} issueMatcher: {
$0.compactDescription == """
failed - Unimplemented: 'Client.endpoint'
"""
}
}
#endif
}
Expand Down