Closed swift-ci closed 4 years ago
@swift-ci create
On master:
/Users/suyashsrijan/Desktop/test.swift:26:3: error: cannot convert value of type 'String' to expected argument type 'Foo'
"foo"
^
/Users/suyashsrijan/Desktop/test.swift:27:3: error: cannot convert value of type 'String' to expected argument type 'Foo'
"bar"
^
The error seems to go away when you insert a cast:
call {
"foo" as Foo
"bar" as Foo
}
Comment by Michael Kao (JIRA)
Ah ok, haven't tried that. But isn't that something the compiler should be able to figure out?
This is intended behavior. Add
static func buildExpression(_ value: Foo) -> Foo { value }
to your function builder to affect how the expressions are type checked. See https://github.com/DougGregor/swift-evolution/blob/function-builders/proposals/XXXX-function-builders.md for more information.
Attachment: Download
Environment
Xcode 11.3 Playground / Swift 5.1.3Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, FunctionBuilder, TypeChecker | |Assignee | None | |Priority | Medium | md5: f3685517f91c2b32760fd3296922b4f3Issue Description:
When using a type conforming to
ExpressibleByStringLiteral
within the FunctionBuilder closure, the compiler seems to have issues.Given the following type:
And using the function builder:
I am able to get this working:
But when adding another String, the compiler throws an error:
I could reproduce the same behavior when using
ExpressibleByIntegerLiteral
.