Skip to content

Poor diagnostic for misspelled enum case name in catch clause #72505

@jrose-signal

Description

@jrose-signal

Description

No response

Reproduction

enum MyError {
    case firstError(String)
    case secondError(Int)
}

func test() throws {}

func client() throws {
    do {
        try test()
    } catch MyError.notFirstError(_) {
        // Expected
    }
}
<source>:11:35: error: '_' can only appear in a pattern or on the left side of an assignment
 9 │     do {
10 │         try test()
11 │     } catch MyError.notFirstError(_) {
   │                                   ╰─ error: '_' can only appear in a pattern or on the left side of an assignment
12 │         // Expected
13 │     }

Expected behavior

type 'MyError' has no member 'notFirstError', which is what you get if you drop the (_).

Environment

Swift version 6.0-dev (LLVM 4d3f797c4fe4835, Swift 784a7c5)
(via swift.godbolt.org)

Additional information

Also occurs in switch cases, unsurprisingly. catch clauses are just where I ran into it.

Extra search tags: underscore, payload

Metadata

Metadata

Assignees

No one assigned

    Labels

    associated valuesFeature → enums: enum cases with associated values (payload)bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationenumFeature → type declarations: Swift enumeration declarationsenum case patternsFeature → patterns: Enumeration case patternsenum casesFeature → enums: Enum casespatternsFeature: patternsswift 6.0type checkerArea → compiler: Semantic analysiswildcard patternFeature → patterns: The wildcard (underscore) pattern

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions