Skip to content

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

@bjhomer

Description

@bjhomer
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

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationgood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions