Skip to content

[SE-0566] Add support for inferring generic arguments of result builder attributes - #86209

Draft
calda wants to merge 16 commits into
swiftlang:mainfrom
calda:cal--infer-result-builder-generics
Draft

calda wants to merge 16 commits into
swiftlang:mainfrom
calda:cal--infer-result-builder-generics

Conversation

@calda

@calda calda commented Dec 25, 2025 •

Copy link
Copy Markdown
Contributor

Swift evolution proposal: [SE-0566] Infer generic arguments of result builder attributes


This PR adds support for inferring generic arguments of result builder attributes.

For example, this sample code was previously rejected with the error "reference to generic type 'ArrayBuilder' requires arguments in <...>", but it now compiles successfully.

@resultBuilder
struct ArrayBuilder<Element> {
  static func buildBlock(_ elements: Element...) -> [Element] {
    elements
  }
}

@ArrayBuilder
var stringArray: [String] {
  "foo"
  "bar"
}

The idea is that we resolve the generic arguments of the result builder type by type checking type-checking the expression Builder.buildFinalResult (or buildPartialBlock / buildBlock, based on the standard result builder precedence rules) against the type (_) -> Result, where Result is the return type of the declaration the result builder is attached to.

So, when we solve ArrayBuilder.buildBlock with the type (_) -> [String], the solver tells us that ArrayBuilder.Element == String.

Solving the constraint in this way ensures we get standard overload resolution behavior in cases where there are multiple valid options for buildFinalResult (etc).

@calda
calda force-pushed the cal--infer-result-builder-generics branch 6 times, most recently from 7d28973 to bb0a46e Compare December 26, 2025 20:19
@calda calda changed the title Add support for inferring generic parameters of result builder attributes Add support for inferring generic arguments of result builder attributes Jan 3, 2026
@calda
calda force-pushed the cal--infer-result-builder-generics branch 2 times, most recently from 51361df to 05f7fef Compare January 4, 2026 16:26
@calda
calda force-pushed the cal--infer-result-builder-generics branch 2 times, most recently from 5266f5f to 76cd5fd Compare March 13, 2026 15:45
@calda
calda force-pushed the cal--infer-result-builder-generics branch from 76cd5fd to f87ce1d Compare November 12, 2026 02:54
@calda calda changed the title Add support for inferring generic arguments of result builder attributes [SE-0566] Add support for inferring generic arguments of result builder attributes Nov 13, 2026
@calda
calda force-pushed the cal--infer-result-builder-generics branch from ecac350 to b23c860 Compare November 13, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant