Closed swift-ci closed 8 years ago
This isn't legal any more, but clearly the compiler should reject it rather than crashing.
Comment by Vladimir (JIRA)
Could you clarify, why this is not legal any more?
Is it because of SE-0066 ? If so, please note that there is a discussion in swift evalution mail list if that proposal should disallow sending emtpy tuple () to func with empty list of parameters. (for example in "[Pre-proposal] Fix function type grammar" thread) with such comments:
"
> Right, there is some impact on existing code that was omitted
> in the proposal. And it wasn't considered during review. Awkward.
Probably because some(many?) people (like me) did not understand that this proposal is much bigger than "Just require parentheses on function types", because IMHO the major idea of this proposal was disallow `Int->Int` syntax but not to disallow void parameter for zero parameter functions.
I hope community will provide opinions regarding this issue and about the decision regarding the void parameter to argument-less functions, and if that decision is really expected and was clearly mentioned in the proposal.
Personally I think we need to implement the proposal in all areas except this one and raise new proposal to make all things clear regarding argument-less functions.
"
Comment by Vladimir (JIRA)
Well.. Actually I thought that SE-0029 was implemented a long time ago, and as soon as we can write the following code currently in 3.0 (Jun 20, 2016), I thought that sending void(empty tuple) to function with empty param list is and will allowed as edge case :
let f: () -> Void = { _ in print("") }
let z : Void = ()
f(())
Actually I still believe in this and hope that the question regarding sending `()` to zero-parameters function should be discussed by the community and decided explicitely, as no one proposal(that I know of) mentions exactly this edge case.
Could you provide any official response to this subject?
I'm not a core team member, but I consider that a bug, not a feature. Why would you want to do this, anyway?
Comment by Vladimir (JIRA)
I see. No, I believe this is not a bug but a feature that come from tuple-splat days and is useful in some cases of functional programming and working with generics, when you can pass result of `-> Void` function as argument to function defined as zero-parameters func or use Void as generic type and () as value to call zero-parameters func.
I guess I should have phrased it as "when do you want to do this?" I believe this still works in the fully-generic case, but if the two-argument case doesn't work I don't see why the zero-argument case should.
Do you have real-world code using this?
Comment by Vladimir (JIRA)
Usually I used/saw this technique : you define a generic func/class with type T that accepts 'item' of type T and 'processor' for that item. Then, inside code of that generic func/class you call 'processor(item)'. Any func defined wihtout parameters now can accept () as argument, so your generic type code works in this case too - it sends () 'item' to processor() which is func with emtpy param list. Given that just func without parameters will not accept () as argument - you will need to wrap the function name with closure {_ in funcWithoutParams}. But probably there is other useful using of that feature.
Comment by Vladimir (JIRA)
Swift Ver. 3.0 (Aug 30, 2016), Platform: Linux (x86_64) - the initial code specified in the issue is compiling and working well.
will wait for SE-0110 implementation ;-)
Environment
Swift Ver. 3.0 (Jun 20, 2016) Target: x86_64-ubuntu-linux-gnuAdditional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | None | |Priority | Medium | md5: 189cf980068cef07ae4c82023ef41ee8Issue Description: