Skip to content

[SR-12063] Swift should warn for switch case '.none' vs '.none?' ambiguity #54499

@keith

Description

@keith
Previous ID SR-12063
Radar None
Original Reporter @keith
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee @theblixguy
Priority Medium

md5: 17a3bec14e602d0feaaa8c2f85e8aae7

Issue Description:

With this code:

enum Foo {
    case bar
    case none
}

let a: Foo? = Foo.none

switch a {
case .none: // Should be '.none?'
    print(".none")
case .bar:
    print(".bar")
default:
    print("default")
}

Everything compiles, but you may have surprising behavior where the `default` case is matched instead of `case .none`.

Following by the example of the great warning you get when you have `let a: Foo? = .none`, it would be great if there was a similar warning for the "ambiguity" here

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationimprovementtype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions