What's wrong with my function builder?

I wrote a dummy function builder and my issue is that with my implementation, I am able to write this:

bar<Int> {
    baz()
    baz()
}

This:

bar<Int> {
    baz()
}

Fails with the following error:

Argument passed to call that takes no arguments

I heard there might be issues with the single argument buildBlock in the current implementation, but I'm not sure of wether it's a bug or if it's me doing something wrong?

Thank you

EDIT: I'm using Xcode b2, but also tested it with the latest Swift trunk snapshot and it didn't change anything.

1 Like

I'm pretty suspicious that your single argument buildBlock doesn't mention T at all. How is the compiler supposed to infer T in that case? What if you add a A.Tag == T clause there?

Even if that fixes it though, I think the error message could use work, so you should consider filing a bug to improve the diagnostic.

Thanks, I updated the gist with this as it wasn't correct given how I want it to work, but it didn't change anything unfortunately.

I also tried explicitly setting the type but it didn't change anything either.

I think this is a bug in the current implementation. If you have zero or one elements in the function builder body, the type checker gets confused by the single-expression closure type inference that would normally be in effect. cc @John_McCall

3 Likes

Thank you! Should I do a bug report?

I don't think you need to, we already have copious reports of this.

1 Like

I see, thanks. Is there a known temporary hack to avoid this issue?

Wrapping the expression in if true { ... } should work, assuming your builder supports buildIf.

1 Like

Thank you

Terms of Service

Privacy Policy

Cookie Policy