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

wrong error message with if-let return type mismatch #35685

Closed
durka opened this issue Aug 15, 2016 · 6 comments
Closed

wrong error message with if-let return type mismatch #35685

durka opened this issue Aug 15, 2016 · 6 comments

Comments

@durka
Copy link
Contributor

durka commented Aug 15, 2016

This function

fn foo() -> bool { if let Some(()) = Some(()) { } else { } }

Produces E0308 (correct) with the message "if-let arms have incompatible types" (nonsense).

@durka
Copy link
Contributor Author

durka commented Aug 15, 2016

@nagisa
Copy link
Member

nagisa commented Aug 15, 2016

This is what is reported for match version of this:

error: match arms have incompatible types [--explain E0308]
 --> <anon>:2:5
2 |>     match Some(()) {
  |>     ^ expected bool, found ()
note: expected type `_`
note:    found type `()`
note: match arm with an incompatible type
 --> <anon>:3:21
3 |>         Some(()) => { }
  |>                     ^^^

I feel like this falls in the same category, and the issue could be fixed by highlighting the branch with conflicting type.

@durka
Copy link
Contributor Author

durka commented Aug 15, 2016

Makes sense, since if let is desugared to match pretty early on. But IMO that error message is wrong too. The arms are compatible with each other, but they don't match the return type of the function. Also, it says "expected type _" and I thought we got rid of that.

@nagisa
Copy link
Member

nagisa commented Aug 15, 2016

I think there’s multiple ways to interpret the message. I guess you’re interpreting it as

match/if-let arms have incompatible types (between branches, i.e. one branch has mismatching type with another)

whereas another entirely valid interpretation is

match/if-let arm(s) have incompatible types (compared to what they ought to be, given the type of the whole expression)

@durka
Copy link
Contributor Author

durka commented Aug 15, 2016

Yes, you're right. Let's add those parentheticals as NOTEs in the error
message :)

On Mon, Aug 15, 2016 at 1:25 PM, Simonas Kazlauskas <
[email protected]> wrote:

I think there’s multiple ways to interpret the message. I guess you’re
interpreting it as

match/if-let arms have incompatible types (between branches, i.e. one
branch has mismatching type with another)

whereas another entirely valid interpretation is

match/if-let arm(s) have incompatible types (compared to what they ought
to be given inferred type of the whole expression)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#35685 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAC3nzG-enCrw-0ALQCFCnJliXVroojgks5qgKEhgaJpZM4Jkguf
.

@Mark-Simulacrum
Copy link
Member

Technically, today's message is correct. Ideally we'd error on the whole expression instead of each arm, but I'm going to close since we no longer say anything about incompatible types of arms.

error[E0308]: mismatched types
 --> test.rs:1:47
  |
1 | fn foo() -> bool { if let Some(()) = Some(()) { } else { } }
  |                                               ^^^ expected bool, found ()
  |
  = note: expected type `bool`
             found type `()`

error[E0308]: mismatched types
 --> test.rs:1:56
  |
1 | fn foo() -> bool { if let Some(()) = Some(()) { } else { } }
  |                                                        ^^^ expected bool, found ()
  |
  = note: expected type `bool`
             found type `()`

error: aborting due to 2 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants