Swift: Using logical operators on Bools as return values from functions that do not return Bool results in a very confusing compiler message.
| Originator: | dcoufal | ||
| Number: | rdar://24934450 | Date Originated: | March 2, 2016 |
| Status: | Open | Resolved: | |
| Product: | Xcode | Product Version: | 7.2 |
| Classification: | Serious Bug | Reproducible: | 100% |
Summary:
This func:
func testFunc() {
return true && true
}
results in this error message:
Binary operator '||' cannot be applied to two 'Bool' operands.
But, the error is that the function does not return Bool, not that the operator is incorrect.
func testFunc() -> Bool {
return true && true
}
This is the correct function.
The bug is that the error message is incorrect. The error message should be something along the lines of:
Unexpected non-void return value in void function
Steps to Reproduce:
Any swift project in XCode 7.2.
Copy and paste above code into a swift file and compile.
Expected Results:
I would expect the error message:
Unexpected non-void return value in void function
Actual Results:
Received the error message:
Binary operator '||' cannot be applied to two 'Bool' operands.
This error message is factually incorrect. The '||' operator is, of course, applicable to Bool operands.
Version:
XCode 7.2
Notes:
Configuration:
Attachments:
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!