Swift "if let" syntax is inconsistent with other "let"

Originator:dvoss.cynergy
Number:rdar://17183868 Date Originated:05-Jun-2014 01:30 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode Version 6.0 (6A215l)
Classification: Reproducible:
 
Summary:
In the "if let x = expr" syntax, "expr" must be an expression of type "T?", but "x" can be left as an inferred type or declared as "T" or "T!" or "T?". The inferred type isn't known, but is certainly not "T?". In other words, you really don't know what the type of "x" is or should be.

I think it would be less confusing if "x" were always inferred to be "T!", or, if explicitly typed, required to be "T!". In other words one could say "if let x : T! = expr" or "if let x = expr", but not "if let x : T = expr" or "if let x : T? = expr".

This would leave "if let" a special case, but at least a well-defined special case. This would also preclude "if let x = expr" where expr is a non-optional type, but that is already an error, so no loss or gain there.

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!