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: usage of '<-' operator on non mutable bindings #1110

Closed
Tracked by #1103
smoothdeveloper opened this issue Apr 24, 2016 · 3 comments
Closed
Tracked by #1103

Comments

@smoothdeveloper
Copy link
Contributor

smoothdeveloper commented Apr 24, 2016

What

Sometimes assignment operator is used on immutable values, currently, for all cases the compilers gives This value is not mutable :

let x = 10
x <- 20

Why

In cases where it is straightforward to devise a fix (changing simple value to mutable), giving help to developers unfamiliar with F# on how to change their code smooths the learning curve.

How

The message could read value 'x' is not mutable, please check that it is declared as mutable: 'let mutable x = 10' if you intend to mutate it.

If it is not easily possible from AST to quote the RHS expression, we can still show the LHS.

@isaacabraham
Copy link
Contributor

isaacabraham commented Apr 26, 2016

I suggest that we might want to go even further than this: -

Values in F# are immutable by default. If you wish to mutate this value, you must explicitly declare it as a mutable variable using the mutable keyword: let mutable x = 10'`

(although we probably would have to drop the RHS)

@isaacabraham
Copy link
Contributor

@smoothdeveloper Could you update the issue with a "what" "why" and "how" as per the other issues? Thanks :-)

@forki
Copy link
Contributor

forki commented May 3, 2016

WIP PR: #1147

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

4 participants