Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12234] Misleading error messages when doing arithmetic between incompatible types #54660

Closed
idrougge opened this issue Feb 19, 2020 · 1 comment
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

Comments

@idrougge
Copy link

Previous ID SR-12234
Radar None
Original Reporter @idrougge
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 11.3.1 (11C504)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: 8ed7d3c61b1ad2446c2f3142f8403046

duplicates:

  • SR-11964 bad diagnostic for mismatched numeric types

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.

@theblixguy
Copy link
Collaborator

Can you try using Xcode 11.4 beta? The new diagnostic architecture should hopefully provide a better diagnostics in situations like this.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants