-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-11792] Function Builder not working with single item in closure #54202
Comments
Comment by Christopher Fuller (JIRA) One thought I had was that possibly we need `buildExpression` to make this work. So the builder could become: @_functionBuilder
public struct ScriptBuilder {
public static func buildExpression(_ step: Step) -> Script {
[step]
}
public static func buildBlock(_ scripts: Script...) -> Script {
scripts.flatMap { $0 }
}
public static func buildIf(_ script: Script?) -> Script {
script ?? []
}
public static func buildEither(first: Script) -> Script {
first
}
public static func buildEither(second: Script) -> Script {
second
}
} But I cannot seem to get `buildExpression` to work … possibly it's not implemented … so am unable to test this theory. |
Hmm, I thought adding a 1. Define a new |
|
@swift-ci create |
Comment by Christopher Fuller (JIRA) @theblixguy Thanks for the quick reply! 👍 I tested both #1 and #2, and they both work. Out of those, #2 seems preferred since it is more concise. But overall I prefer the convenience initializer approach to either of those two options, as it allows the call-site to look as expected. And thanks for the link and info on `buildExpression`. |
Comment by Christopher Fuller (JIRA) Does anyone know if `buildExpression` is required to make this work? |
I tried it and it didn’t work. I think there’s some issues with single expression closures that are yet to be resolved, |
Comment by Christopher Fuller (JIRA) Ah, okay. And I can see that single expression functions do in fact work… @ScriptBuilder
func makeScript() -> Script {
ExampleStep()
} output: buildBlock called [__lldb_expr_1.ExampleStep()]
[__lldb_expr_1.ExampleStep()] So the issue indeed appears to be limited to the single expression closures specifically. |
Comment by Christopher Fuller (JIRA) updated the ticket title to reflect closures specifically |
This is covered by SR-11628 |
Additional Detail from JIRA
md5: e95e737358935b21a7b4720012df6a58
duplicates:
Issue Description:
Provided:
Expected:
Actual:
This can be solved by adding this initializer:
Then you would get this output:
But my expectation is that the convenience initializer is not needed and that the buildBlock method in the builder should be called in the single case.
Please advise. Thanks so much!
The text was updated successfully, but these errors were encountered: