pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.35k stars 1.44k forks source link

Xcode16 and testing `store.receive` with a `case ...(Result<Void, Error>)` action #3380

Closed oronbz closed 1 month ago

oronbz commented 1 month ago

Description

Hi there’s an issue with Xcode16 and testing store.receive on a case voidResult(Result<Void, Error>) action, I’ve managed to reproduce it with a minimal project, and it only happens when using Result<Void, …> and not with Result<String, …>. It also happens only on await store.receive(\.voidResult.success) and not if I omit the .success or .failure case path like this:await store.receive(\.voidResult) Example Reducer:

@Reducer
struct Feature: Reducer {
    @ObservableState
    struct State: Equatable {}

    enum Action {
        case onAppear
// Will compile with other than `Void`
        case voidResult(Result<Void, Error>)
    }

    var body: some Reducer<State, Action> {
        Reduce<State, Action> { state, action in
            switch action {
            case .onAppear:
                return .run { send in
                    await send(.voidResult(.success(())))
                }
            case .voidResult:
                return .none
            }
        }
    }
} 

Test which fails to compile:

final class ResultTestFailTests: XCTestCase {
    @MainActor
    func testVoidResult() async {
        let store = TestStore(initialState: Feature.State()) {
            Feature()
        }

        await store.send(.onAppear)
        // Build fails
        await store.receive(\.voidResult.success)

        // Build succeed
        // await store.receive(\.voidResult)
}

Error (partial):

1.  Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.  Compiling with effective version 5.10
3.  While evaluating request IRGenRequest(IR Generation for file "/Users/oronb/Developer/iOS/ResultTestFail/ResultTestFailTests/ResultTestFailTests.swift")
4.  While emitting IR SIL function "@$s19ResultTestFailTestsAAC08testVoidA0yyYaF".
 for 'testVoidResult()' (at /Users/oronb/Developer/iOS/ResultTestFail/ResultTestFailTests/ResultTestFailTests.swift:14:5)
0  swift-frontend           0x00000001063af0fc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001063ad350 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001063af6c8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000019fe22584 _sigtramp + 56
4  swift-frontend           0x000000010243354c swift::Mangle::ASTMangler::appendConcreteProtocolConformance(swift::ProtocolConformance const*, swift::GenericSignature) + 1020
5  swift-frontend           0x00000001024338c0 swift::Mangle::ASTMangler::appendConcreteProtocolConformance(swift::ProtocolConformance const*, swift::GenericSignature) + 1904
6  swift-frontend           0x0000000101373ee0 swift::irgen::IRGenMangler::mangleSymbolNameForMangledConformanceAccessorString(char const*, swift::CanGenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 208
7  swift-frontend           0x00000001012efa28 swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature, bool) + 416
8  swift-frontend           0x0000000101286ca4 void llvm::function_ref<void (swift::GenericRequirement)>::callback_fn<emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool)::$_0>(long, swift::GenericRequirement) + 628
9  swift-frontend           0x00000001012dbc28 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&) + 220
10 swift-frontend           0x000000010127e020 emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool) + 1368

Minimal project reproducing this (by testing - CMD+U)

Checklist

Expected behavior

No response

Actual behavior

No response

Reproducing project

https://github.com/oronbz/tca-xcode16-buildfails-voidresulttest

The Composable Architecture version information

1.15.0

Destination operating system

iOS 18

Xcode version information

Version 16.0 (16A242)

Swift Compiler version information

No response

stephencelis commented 1 month ago

This is a duplicate of:

And unfortunately a bug in Swift, not the library. As such I'm going to convert to a discussion, and I'd encourage folks encountering the issue to submit it to Apple's Swift repo. Unfortunately it doesn't look like the original report followed up with a link to an Apple issue, so I'm not sure where/if it was filed.