Skip to content

Compiler Regression in Swift 6/Xcode 16b6 #76120

Open
@rhysm94

Description

@rhysm94

Description

I've encountered an unexpected regression when compiling a project that uses the CasePaths library. The code compiles as expected in Xcode 15.4, but in Xcode 16 beta 6, I get a non-zero error code when compiling.

For context, CasePaths is a library which allows developers to create KeyPaths to enum cases. It also includes dynamicMemberLookup support for chaining into enum cases, as well as providing manual implementations of what the @CasePathable macro would generate for common types, like Result and Optional. It generates a holder type called Cases, which is where the generated key paths are placed.

Say I have the following enum:

public enum Action {
  case didSucceed(Result<Void, any Error>)
}

With the CasePath library, I'd be able to create a KeyPath to the didReceiveValue case, and because Result has manual implementations, I'd be able to chain that KeyPath to either the Success or Failure case. i.e. I could write either of these lines of code and have them compile correctly:

let actionCase = \Action.Cases.didSucceed
let resultSuccessCase = \Action.Cases.didSucceed.success

However, as of the latest version of Xcode 16 and the Swift compiler, only let actionCase ... compiles. If I include the chained .success, compilation fails. The same applies for the .failure case too.

Strangely, if I add another case where Result has a different Success case, e.g.

case didReceiveValue(Result<Int, any Error>)

everything works fine, and I can write

let receiveValueSuccessCase = \Action.Cases.didReceiveValue.success

I've pushed a repo which includes the bug, along with the most recent compilation backtrace.
https://github.com/rhysm94/VoidCasePathBug/

Reproduction

This file, in my repo, contains the lines of code that now fail to compile.
I've trimmed it down as much as possible, so it only includes the lines which demonstrate the bug.

If you comment out/remove the .success from static let bug, the code will compile.

https://github.com/rhysm94/VoidCasePathBug/blob/main/Sources/VoidCasePathBug/VoidCasePathBug.swift

Expected behavior

I expect compilation to succeed, as it does in Xcode 15.4. I've tested my repository on an Xcode 15.4 install, changing only the swift tools version to 5.10, and it builds successfully.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @dynamicMemberLookupFeature → attributes: the @dynamicMemberLookup attributebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featurescrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionskey pathsFeature: key paths (both native and Objective-C)type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions