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-11964] bad diagnostic for mismatched numeric types #54389

Closed
mattneub opened this issue Dec 18, 2019 · 11 comments
Closed

[SR-11964] bad diagnostic for mismatched numeric types #54389

mattneub opened this issue Dec 18, 2019 · 11 comments
Assignees
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 good first issue Good for newcomers type checker Area → compiler: Semantic analysis

Comments

@mattneub
Copy link

Previous ID SR-11964
Radar rdar://problem/58028105
Original Reporter @mattneub
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11.3

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

md5: 679d6d75f86aaa3d7603e69fb7170afb

is duplicated by:

  • SR-12234 Misleading error messages when doing arithmetic between incompatible types

Issue Description:

        let d = 0.2
        let x = self.view.frame.size.width * d

The actual error here is obviously that `d` is a Double but `self.view.frame.size` is a CGFloat. However, the error message reads:

Value of type '(CGRect) -> CGRect' has no member 'size'

That is quite a fascinating diagnostic. Notice that this is not saying that CGRect has no `size`. It is talking about a function that takes a CGRect and returns a CGRect. I cannot imagine what function it has in mind!

@theblixguy
Copy link
Collaborator

Can you try this on a recent development snapshot from swift.org? The diagnostics might have been improved.

@mattneub
Copy link
Author

@theblixguy Actually what I get on the most recent snapshot (2019-12-16 (a)) is "Cannot assign to property: 'self' is immutable", which is insane.

@beccadax
Copy link
Contributor

@swift-ci create

@beccadax
Copy link
Contributor

beccadax commented Jan 7, 2020

@xedin says the diagnostic is referring to frame(forAlignmentRect:). The old diagnostic disfavored this overload vs. the frame property; the new one considers both equally valid and ends up talking about the method for some reason.

@hborla
Copy link
Member

hborla commented Feb 6, 2020

This is a good starter bug! Here's a reproducer:

import AppKit
let view = NSView()
_ = view.frame.width * Double(0.8)

which currently produces:

error: value of type '(NSRect) -> NSRect' (aka '(CGRect) -> CGRect') has no member 'width'
_ = view.frame.width * Double(0.8)
    ~~~~~~~~~~ ^~~~~

@hborla
Copy link
Member

hborla commented Feb 6, 2020

A simpler case without AppKit:

struct Rect {
  let width: Int
  let height: Int
}

class Frame {
  func rect(width: Int, height: Int) -> Rect {
    Rect(width: width, height: height)
  }

  let rect: Rect
}

func foo(frame: Frame) {
  frame.rect.width + 10.0
}
error: value of type '(Int, Int) -> Rect' has no member 'width'
  frame.rect.width + 10.0
  ~~~~~~~~~~ ^~~~~

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 6, 2020

Comment by Vuk (JIRA)

Is this still available? I would like to give it a shot.

@hborla
Copy link
Member

hborla commented Feb 7, 2020

vukrado (JIRA User) yes, this is still available! Please feel free to ask questions if you need help.

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 7, 2020

Comment by Vuk (JIRA)

Sounds good thank you @hborla! Can I go ahead and assign myself to the issue?

@hborla
Copy link
Member

hborla commented Feb 7, 2020

vukrado (JIRA User) yes, please assign to yourself!

@xedin
Copy link
Member

xedin commented Feb 13, 2020

Has been fixed by #29795 vukrado (JIRA User) Thank you for the patch!

@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 good first issue Good for newcomers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

6 participants