Skip to content

expected &someEnum but found an enum or structure pattern is misleading #7867

Closed
@ozten

Description

@ozten

I've had a hard time learning match because this error message is misleading.

Steps to reproduce:

  1. Compile a small program which uses extra::json with
match value {
    Number(n) => {
        println(fmt!("%?\n", n))
    },
    _ => {
        println(~"Doh")
    }
}
  1. Note compiler error

Actual:

json.rs:20:25: 20:34 error: mismatched types: expected `&extra::json::Json` but found an enum or structure pattern
json.rs:20                          Number(n) => {
                                    ^~~~~~~~~
error: aborting due to previous error

Expected:

error: mismatched types: expected `&extra::json::Json` but found enum extra::json::Json

or more generally
expected &someEnum but found enum T

Great work on the rest of the error message, BTW. I like the line number and arrow.

I eventually figured out that Number is an enum value of extra::json::Json and the fix is:

match value {
    & Number(n) => {
        println(fmt!("%?\n", n))
    },
    _ => {
        println(~"Doh")
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions