Skip to content

When using @DependencyClient macro, closures with mandatory return don't use the unimplemented version on tests #183

Open
@gpambrozio

Description

@gpambrozio

Description

When using @DependencyClient macro in a client that has closures with mandatory returns, when using these closures in a test without overriding them we don't get errors about the method not being implemented.

According to this message from Brandon this is related to a swift bug. Given that I'd suggest to at least add a note to the documentation mentioning that, instead of having a closure such as { _ in true }, we unfortunately still have to use { _ in unimplemented(placeholder: true) }

See also this Slack thread

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

The test shown should have 2 errors.

Actual behavior

The test only produces one error.

Steps to reproduce

Simple Client:

import Dependencies
import DependenciesMacros

@DependencyClient
struct SimpleClient {
    var noReturn: () -> Void
    var withBoolReturn: () -> Bool = { true }
}

extension SimpleClient: TestDependencyKey {
    public static let testValue = SimpleClient()
}

extension DependencyValues {
    var simpleClient: SimpleClient {
        get { self[SimpleClient.self] }
        set { self[SimpleClient.self] = newValue }
    }
}

This test should have 2 failures but only shows one:

import Dependencies
import XCTest
@testable import TCATest

final class TCATestTests: XCTestCase {
    func testExample() throws {
        @Dependency(\.simpleClient) var simpleClient
        _ = simpleClient.withBoolReturn()
        simpleClient.noReturn()
    }
}

Dependencies version information

1.2.1

Destination operating system

iOS

Xcode version information

15.2

Swift Compiler version information

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    apple bugSomething isn't working due to a bug on Apple's platforms.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions