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-15165] Roundabout error message is viewed when Int is passed to where NSNumber is expected. #57488

Closed
YOCKOW opened this issue Sep 7, 2021 · 6 comments
Assignees
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement

Comments

@YOCKOW
Copy link
Collaborator

YOCKOW commented Sep 7, 2021

Previous ID SR-15165
Radar rdar://problem/82828226
Original Reporter @YOCKOW
Type Improvement
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee @YOCKOW
Priority Medium

md5: ee5ef301fae73e1dec12f385ba78f3ac

Issue Description:

Given the following code:

import Foundation

func f(_ n: NSNumber) {}

let int: Int = 0

f(int)
/*
⛔️ error: cannot convert value of type 'Int' to expected argument type 'NSNumber'
f(int)
 ^
 NSNumber( )
 */

// Fix it as advised...
f(NSNumber(int))
/*
⛔️ error: no exact matches in call to initializer
f(NSNumber(int))
 ^
Foundation.NSNumber:41:12: note: incorrect labels for candidate (have: '(_:)', expected: '(value:)')
   public init(value: Int)
          ^
Foundation.NSNumber:2:42: note: incorrect labels for candidate (have: '(_:)', expected: '(integerLiteral:)')
   @nonobjc required public convenience init(integerLiteral value: Int)
                                        ^
 */

f(NSNumber(value: int)) // ✅ OK

I believe NSNumber(value: ) should be suggested first.

@typesanitizer
Copy link

@swift-ci create

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 9, 2021

Comment by jiaren wang (JIRA)

Could I get some hints?

@typesanitizer
Copy link

cc @xedin for implementation suggestions 🙂

@xedin
Copy link
Member

xedin commented Sep 9, 2021

I think all we need to do here is to detect that `toType` is `NSNumber` and add a label to the fix-it here - https://github.com/apple/swift/blob/main/lib/Sema/CSDiagnostics.cpp#L2876

@xedin
Copy link
Member

xedin commented Sep 16, 2021

Fixed by #39261 Please use next available toolchain to verify and close.

@YOCKOW
Copy link
Collaborator Author

YOCKOW commented Oct 3, 2021

Thank you for having worked on it.

@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
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement
Projects
None yet
Development

No branches or pull requests

4 participants