Skip to content

Parameter type cannot be inferred from contextual type in pack expansion on a closure associated with a result builder #82246

Open
@ccerino-adobe

Description

@ccerino-adobe

Description

When defining a closure that leverages parameter packs, the compiler can't infer the parameter type from the values in the closure.

Reproduction

Below is a code snippet from the attached example project.

@resultBuilder
enum ShowcaseContentBuilder {
    public static func buildBlock<each Content: View, ColumnType: ShowcaseColumnRepresentable>(_ content: repeat ShowcaseRow<ColumnType, each Content>) -> (repeat ShowcaseRow<ColumnType, each Content>) {
        (repeat each content)
    }
}

Showcase(title: "Showcase", columns: IconTestAsset.allCases) {
  ShowcaseRow(name: "Test 1") { icon in
    Image(systemName: icon.rawValue)
  }
  ShowcaseRow(name: "Test 2") { icon in
    Image(systemName: icon.rawValue)
  }
}

Expected behavior

The above code should be able to to infer icon is of type IconTestAsset, but the code fails to compile with the following errors:

  • Generic parameter 'each EntryContent' could not be inferred
  • Cannot infer type of closure parameter 'icon' without a type annotation
Image

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0

Additional information

I joined a 1on1 lab with folks from the Swift team during WWDC and they suggested this is a dupe of #78426, but they encouraged me to file a new issue and share my example code

ResultBuilderTest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsresult buildersFeature: Result builderstype checkerArea → compiler: Semantic analysisvariadic parametersFeature → declarations → function parameters: Variadic function parameters

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions