Skip to content

[SR-184] Wrong diagnostic when uninitialized optional is chained #42806

Closed
@jckarter

Description

@jckarter
Previous ID SR-184
Radar None
Original Reporter @jckarter
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee @gregomni
Priority Medium

md5: baeea16bd3d67c1a509c4f3789ecf120

Issue Description:

The following code complains that x is used by a closure before being initialized, instead of more accurately complaining that it's optional-chained (or just generically that it's used):

let x: String?

if [1,2,3].contains(2) {
    x = "lala"
} 
// else {
    // x = nil
// }

print(x)
print(x?.characters.count)

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions