- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: 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.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Description
I've had a hard time learning match because this error message is misleading.
Steps to reproduce:
- Compile a small program which uses extra::json with
match value {
    Number(n) => {
        println(fmt!("%?\n", n))
    },
    _ => {
        println(~"Doh")
    }
}
- 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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: 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.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.