Swift: compiler should not warn about non-use of Void? return type

Originator:garth
Number:rdar://22426271 Date Originated:25-Aug-2015 02:19 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7 beta 6
Classification:Other Bug Reproducible:Always
 
Thanks for adding the try? keyword to beta 6. This is a helpful addition to the language.

Unfortunately, it has the side effect of promoting all functions to value-returning status, even if the function being called returns Void. So the compiler will issue a warning if the value isn’t consumed.

This isn’t an issue with value-returning functions, since the value would have to be consumed anyway in order to avoid a warning. But it would be nice to be able to use the construction

    try? funcReturningVoid()

without further embellishment or warnings. As it is now, you must write

    _ = try? funcReturningVoid()

to suppress the warning. This is just clutter; the intention to ignore the error is already clear from the code. 

In fact, I’d speculate that the underlying check to see if a Void? value is consumed is significantly more likely to generate a spurious warning than a helpful one. Wouldn’t it make sense to suppress the warning in the case of Void?

I can understand the desire for consistency. But on the other hand, warnings need not be held to the same standard as actual language constructs. And they should be more helpful than annoying.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!