-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
Resultbuilders with Parameter Packs that compile in Xcode 16.4 stop compiling in Xcode 26 beta 3. It seems that the Protocol requirement is causing the issue. Removing the protocol requirements makes the code compile again. (See commented out version in the example).
Reproduction
import Foundation
/// Not compiling Version
protocol Element: Sendable {}
struct A<each E>: Sendable {
init(@ElementsBuilderWithProtocol elements: () -> (repeat each E)) {
self.elements = elements()
}
let elements: (repeat each E)
}
/// Compiling Version
//struct A<each E>: Sendable {
// init(@ElementsBuilderWithoutProtocol elements: () -> (repeat each E)) {
// self.elements = elements()
// }
// let elements: (repeat each E)
//}
let a = A {
if true {
1
"Hello"
} else {
Date()
}
}
// Error Messages:
// Generic parameter 'each E' could not be inferred
// Type '(Int, String)' cannot conform to 'Element'
// MARK: - Failing ResultBuilder
@resultBuilder struct ElementsBuilderWithProtocol {
static func buildBlock<each E: Element>(_ component: repeat each E) -> ((repeat each E)) {
(repeat each component)
}
static func buildEither<each E: Element, each F: Element>(first component: (repeat each E)) -> ConditionalElements<repeat each E>.ConditionalElseElement<repeat each F> {
ConditionalElements.ConditionalElseElement(ifElement: component, elseElement: nil)
}
static func buildEither<each E: Element, each F: Element>(second component: (repeat each F)) -> ConditionalElements<repeat each E>.ConditionalElseElement<repeat each F> {
ConditionalElements.ConditionalElseElement(ifElement: nil, elseElement: component)
}
}
extension Int: Element {}
extension String: Element {}
extension Date: Element {}
// MARK: - Working ResultBuilder
@resultBuilder struct ElementsBuilderWithoutProtocol {
static func buildBlock<each E>(_ component: repeat each E) -> ((repeat each E)) {
(repeat each component)
}
static func buildEither<each E, each F>(first component: (repeat each E)) -> ConditionalElements<repeat each E>.ConditionalElseElement<repeat each F> {
ConditionalElements.ConditionalElseElement(ifElement: component, elseElement: nil)
}
static func buildEither<each E, each F>(second component: (repeat each F)) -> ConditionalElements<repeat each E>.ConditionalElseElement<repeat each F> {
ConditionalElements.ConditionalElseElement(ifElement: nil, elseElement: component)
}
}
// MARK: - Shared ResultBuilder Helper
public struct ConditionalElements<each IfElement> {
public struct ConditionalElseElement<each ElseElement> {
init(ifElement: (repeat each IfElement)?, elseElement: (repeat each ElseElement)?) {
self.ifElement = ifElement
self.elseElement = elseElement
}
let ifElement: (repeat each IfElement)?
let elseElement: (repeat each ElseElement)?
}
}
Expected behavior
The code should compile the same way as in Xcode 16.4
Environment
Xcode 26 beta 3
swift-driver version: 1.127.8 Apple Swift version 6.2 (swiftlang-6.2.0.13.10 clang-1700.3.13.4)
Target: arm64-apple-macosx26.0
Xcode 16.4
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx16.0
macOS 26.0 Beta (25A5306g)
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels