Parameter packs in result builder error – Type '(repeat each Content)' does not conform to protocol 'FormComponent'

Hi, I'm exploring using the new parameter packs in result builders, as is now done in SwiftUI, but I'm getting this weird error (even though I'm essentially following how SwiftUI does it):

public struct FormBuilder {
    public static func buildBlock<each Content: FormComponent>(_ content: repeat each Content) -> TupleFormComponent<(repeat each Content)> {
        return TupleFormComponent<each Content>(content: content)

Gives the error Type '(repeat each Content)' does not conform to protocol 'FormComponent'.

The FormComponent struct looks like this:

public struct TupleFormComponent<each Component: FormComponent>: FormComponent { ... }

So to me it feels like this should work. Let me know if you think I made any glaring mistakes!

Your return type has extra parens, so it’s trying to make a TupleFormComponent of one element, a tuple (which presumably gets redundantly parenthesized within the implementation of TupleFormComponent), rather than the many-element pack you’re using in the body of the function.

Good candidate for a special-case diagnostic, perhaps?

1 Like