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-9201] Incorrect error message when using optional chaining #51692

Closed
bjhomer opened this issue Nov 7, 2018 · 6 comments
Closed

[SR-9201] Incorrect error message when using optional chaining #51692

bjhomer opened this issue Nov 7, 2018 · 6 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

Comments

@bjhomer
Copy link
Contributor

bjhomer commented Nov 7, 2018

Previous ID SR-9201
Radar None
Original Reporter @bjhomer
Type Bug
Status Resolved
Resolution Done
Environment

Swift 4.2
Swift 5 (master, as of Nov 6, 2018)

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

md5: c734879d228c03881746c3e4d483304a

Issue Description:

An incorrect error message is produced here:

struct Thing {
  func produceDoubleOptional() -> Int?? { return 3 }
}

let optThing: Thing? = Thing()

// error: Value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let _: Int? = optThing?.produceDoubleOptional()

The error is suggesting a change like this:

let _: Int? = (optThing?.produceDoubleOptional())!

But

@belkadan
Copy link
Contributor

belkadan commented Nov 7, 2018

cc @xedin. Starter bug?

@xedin
Copy link
Member

xedin commented Nov 7, 2018

I actually don't think it's a problem because the contextual type is `Int?` which matches what `(optThing?.produceDoubleOptional())!` is going to produce by unwrapping one level of optional from `Int??`. @bjhomer Could you please clarify what seems to be the issue here?

@belkadan
Copy link
Contributor

belkadan commented Nov 7, 2018

The message is wrong, not the fix-it.

@bjhomer
Copy link
Contributor Author

bjhomer commented Nov 7, 2018

It's telling me that I need to turn an `Int?` into an `Int`, when I actually need to turn an `Int??` into an `Int?`. There is no reason the compiler should telling me something needs to be unwrapped into an plain `Int` here, because nothing requires a plain `Int`.

@xedin
Copy link
Member

xedin commented Nov 7, 2018

@bjhomer Ah the error message itself, I see, sorry! Yes, that's definitely a starter bug.

@xedin
Copy link
Member

xedin commented Jan 26, 2019

@bjhomer Issue has been resolved by #22050 thanks to @theblixguy for contribution! Please use next available snapshot to verify.

@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
Projects
None yet
Development

No branches or pull requests

3 participants