[SR-12234] Misleading error messages when doing arithmetic between incompatible types #54660
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
type checker
Area → compiler: Semantic analysis
Environment
Xcode 11.3.1 (11C504)
Additional Detail from JIRA
md5: 8ed7d3c61b1ad2446c2f3142f8403046
duplicates:
Issue Description:
When trying to subtract an Int from a CGFloat, the compiler usually gives an error like "Binary operator '-' cannot be applied to operands of type 'CGFloat' and 'Int'"
However, when doing the same arithmetic on this expression in a UIViewController:
let tableInsets: Int = 44
let height = self.view.frame.height - tableInsets
You get this very confusing error message: "Value of type '(CGRect) -> CGRect' has no member 'height'"
Simply assigning self.view.frame.height to a local variable and doing the arithmetic there is enough to get the expected error message about binary operator.
The text was updated successfully, but these errors were encountered: