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

Improve Error Reporting: Show better error when using ref cell instead of not #1276

Closed
Tracked by #1103
isaacabraham opened this issue Jun 22, 2016 · 1 comment
Closed
Tracked by #1103

Comments

@isaacabraham
Copy link
Contributor

isaacabraham commented Jun 22, 2016

What

The following code snippet leads to the resulting error message: -

let x = 5
if !x then "foo" else "bar"

This expression was expected to have type bool ref but here has type int

Why

The error is likely to occur for newcomers to the language who expect it to provide negation behaviour, when F# sees it as ref cell deferefencing, hence the confusing error message. With the improved support for implicit handling of rec cells through the mutable keyword, this error could be reworded to explain that perhaps they meant not instead of !.

How

Suggest an error wording as follows: -

The ! operator is used to dereference a ref cell. Did you want to negate the expression instead? If so, consider using 'not expression' instead.

@isaacabraham
Copy link
Contributor Author

Links to #1275

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

1 participant