Per the syntactic transformation, this closure becomes:
Schema<String> {
let v0 = Component()
let v1 = Component()
return Builder<String>.buildBlock(v0, v1)
}
Note that there's no "context" for the initializers of v0
and v1
, hence the error. If you add buildExpression
to your function builder, like this:
static func buildExpression(_ component: Component<Root>) -> Component<Root> {
component
}
then the closure is transformed to:
Schema<String> {
let v0 = Builder<String>.buildExpression(Component())
let v1 = Builder<String>.buildExpression(Component())
return Builder<String>.buildBlock(v0, v1)
}
and all your examples work. (Note: I also had to fix your buildBlock
to be variadic with ...
rather than take an array).
Please try with buildExpression
---which is, intentionally, the only way in which one can have the builder type influence the types of the subexpressions---and see if your statement above still holds.
Doug