Skip to content

Swift 6.4: ternary with a doubly-labelled tuple result fails to type-check #91701

Description

@strike19

Description

Swift 6.4: ternary with a doubly-labelled tuple result fails to type-check

Filed against: Swift compiler (Xcode 27.0 beta)
Date: 2026-08-25
Reporter: OrcusKern project


Summary

In Swift 6.4 (Xcode 27.0 beta), a ternary conditional expression whose
result type is a tuple with labels at both the outer and the inner
level
fails to type-check. The compiler cannot produce a diagnostic and
emits its internal fallback message:

error: failed to produce diagnostic for expression;
       please submit a bug report (https://swift.org/contributing/#reporting-bugs)

The same code compiles without error or warning in Swift 6.2
(Xcode 26.6).

Environment

Failing Xcode 27.0 beta, build 27A5237lApple Swift version 6.4 (swiftlang-6.4.0.30.4 clang-2100.3.30.1)
Working Xcode 26.6, build 17F113 — SDK MacOSX26.5
Host macOS 26.6.2 (build 25G83), Apple Silicon (arm64)
Command xcrun swiftc -typecheck reproducer.swift

Reproducer

Six lines, no imports, no generics, no map:

func f() {
    let a = (x: Int64(0), y: Int64(0))
    let b = (x: Int64(1), y: Int64(1))
    let r: (p: (x: Int64, y: Int64), q: (x: Int64, y: Int64)) =
        (a.x, a.y) <= (b.x, b.y) ? (a, b) : (b, a)
    _ = r
}

Expected: compiles, as it does in Swift 6.2.
Actual: error: failed to produce diagnostic for expression on the
line holding the ternary.

Reduction — what switches the bug off

Each row changes exactly one thing against the reproducer above.
All five variants compile under Swift 6.2; only two still fail under 6.4.

Variant Change Swift 6.2 Swift 6.4
Reproducer ok error
A inner labels removed: (p: (Int64, Int64), q: (Int64, Int64)) ok ok
B outer labels removed: ((x: Int64, y: Int64), (x: Int64, y: Int64)) ok ok
C if/else instead of the ternary ok ok
D Int instead of Int64 ok error

So the trigger is labels on both nesting levels, combined with the
ternary conditional
. Removing the labels on either level, or replacing
the ternary with an if/else, makes it compile. The element type is
irrelevant.

Workaround

Replace the ternary with an if/else:

let r: (p: (x: Int64, y: Int64), q: (x: Int64, y: Int64))
if (a.x, a.y) <= (b.x, b.y) { r = (a, b) } else { r = (b, a) }

Related but distinct

failed to produce diagnostic for expression is the type checker's
generic fallback, so it covers many unrelated causes. I checked the
eleven issues filed against swiftlang/swift since June 2026 carrying
that exact message (as of 2026-08-25); none matches this trigger:

Issue Its trigger
#91612 typed throws, error type differs only in generic arguments
#91587 comparison between Character and String.Index
#91518 mixed-type array literal passed to Set()
#91215 @ViewBuilder func with switch over Result
#91156 optional-chained Int? assigned to Int64?
#90805 bad ?? expression given to a CChar initialiser
#90780 closure with disagreeing inferred return types
#90733 invalid key path in constrained dynamic member lookup
#90492 type(of:) referenced as a first-class function
#90322 FRT from an array cast as AnyObject
#85133 no reproducer given

#90780 is the nearest — also a closure whose return types cannot be
reconciled. This report is distinct: the minimal reproducer contains no
closure at all
, no optionals, no generics and no map. It is a plain
let binding with an explicitly written tuple type and a ternary. The
original real-world occurrence did involve a map closure, which is why
the two can look alike at first glance.

Real-world impact

Found while building an existing, previously clean Swift 6 package
against the Xcode 27 beta toolchain. One expression in the whole
package triggers it
, in a closure returning a pair of coordinate
tuples:

let paare = segmente.map { s -> (p: (x: Int64, y: Int64), q: (x: Int64, y: Int64)) in
    let a = ganz(s.a), b = ganz(s.b)
    return (a.x, a.y) <= (b.x, b.y) ? (a, b) : (b, a)
}

The build stops there; nothing else in the package fails. Since the
compiler emits no usable diagnostic, the cause is not discoverable from
the message alone — it took bisecting the expression to find it.

Reproduction

// Swift 6.4 (Xcode 27.0 beta 27A5237l):
//   error: failed to produce diagnostic for expression
// Swift 6.2 (Xcode 26.6): compiles cleanly.
//
//   xcrun swiftc -typecheck 2026-08-25-reproducer.swift

func f() {
    let a = (x: Int64(0), y: Int64(0))
    let b = (x: Int64(1), y: Int64(1))
    let r: (p: (x: Int64, y: Int64), q: (x: Int64, y: Int64)) =
        (a.x, a.y) <= (b.x, b.y) ? (a, b) : (b, a)
    _ = r
}

Expected behavior

Hopefully compiles without error for 27 version once rolled out.

Environment

| Failing | Xcode 27.0 beta, build 27A5237lApple Swift version 6.4 (swiftlang-6.4.0.30.4 clang-2100.3.30.1) |
| Working | Xcode 26.6, build 17F113 — SDK MacOSX26.5 |
| Host | macOS 26.6.2 (build 25G83), Apple Silicon (arm64) |
| Command | xcrun swiftc -typecheck reproducer.swift |

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage neededThis issue needs more specific labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions