Skip to content

[Compile Time Constant Extraction] Handle cases where variables with attached result builders are initialized without builder syntax #79400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

venkatesh5789
Copy link
Contributor

@venkatesh5789 venkatesh5789 commented Feb 14, 2025

There was a bug where in cases such as the following:

public protocol FooProvider {
    @FooBuilder
    static var foos: [Foo] { get }
}

If a struct that implements FooProvider just initialized the array directly, as opposed to using the result builder syntax, then the result was unexpectedly a result builder with empty members.

public struct MyFooProviderInferredWithArrayInitialization: FooProvider {
    public static var foos: [Foo] = [
        Foo(...),
        Foo(...),
    ]
}

This PR now ensures that the .swiftconstvalues will contain the correct Array representation.

{
        "label": "foos",
         .
         .
        .
        "valueKind": "Array",
        "value": [
          {
            "valueKind": "InitCall",
            "value": {
              "type": "ExtractResultBuilders.Foo",
              "arguments": [
                {
                  "label": "name",
                  "type": "Swift.String",
                  "valueKind": "RawLiteral",
                  "value": "MyFooProviderInferredWithArrayReturn.foos.1"
                }
              ]
            }
          },
          {
            "valueKind": "InitCall",
            "value": {
              "type": "ExtractResultBuilders.Foo",
              "arguments": [
                {
                  "label": "name",
                  "type": "Swift.String",
                  "valueKind": "RawLiteral",
                  "value": "MyFooProviderInferredWithArrayInitialization.foos.2"
                }
              ]
            }
          }
        ]
      }

Resolves rdar://144796012

…attached result builders are initialized without builder syntax
@venkatesh5789
Copy link
Contributor Author

@swift-ci test

@venkatesh5789 venkatesh5789 merged commit 38cbdf8 into swiftlang:main Feb 24, 2025
5 checks passed
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.

2 participants