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

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

Open
jrose-signal opened this issue Mar 22, 2024 · 1 comment
Open

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

jrose-signal opened this issue Mar 22, 2024 · 1 comment
Labels
associated values Feature → enums: enum cases with associated values (payload) 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 enum case patterns Feature → patterns: Enumeration case patterns enum cases Feature → enums: Enum cases enum Feature → type declarations: Swift enumeration declarations patterns Feature: patterns swift 6.0 type checker Area → compiler: Semantic analysis wildcard pattern Feature → patterns: The wildcard (underscore) pattern

Comments

@jrose-signal
Copy link

jrose-signal commented Mar 22, 2024

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

@jrose-signal jrose-signal added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 22, 2024
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation patterns Feature: patterns wildcard pattern Feature → patterns: The wildcard (underscore) pattern type checker Area → compiler: Semantic analysis associated values Feature → enums: enum cases with associated values (payload) enum Feature → type declarations: Swift enumeration declarations enum cases Feature → enums: Enum cases swift 6.0 enum case patterns Feature → patterns: Enumeration case patterns and removed triage needed This issue needs more specific labels labels Mar 23, 2024
@AnthonyLatsis
Copy link
Collaborator

Smaller test case:

enum E {
    case firstError(String)
}

func test(e: E) {
  if case E.notFirstError(_) = e {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
associated values Feature → enums: enum cases with associated values (payload) 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 enum case patterns Feature → patterns: Enumeration case patterns enum cases Feature → enums: Enum cases enum Feature → type declarations: Swift enumeration declarations patterns Feature: patterns swift 6.0 type checker Area → compiler: Semantic analysis wildcard pattern Feature → patterns: The wildcard (underscore) pattern
Projects
None yet
Development

No branches or pull requests

2 participants