Are let declarations allowed?
phase opened this issue · 6 comments
let
isn't shown as a valid way to assign variables, but it's used in Implicit Reference Types.
static void inc(int^ i, int n)
{
let newValue = i + 1 // no de-referencing required
*i = newValue // assign the new value to the reference target
}
Many pages of the language reference were written quite some time ago and need to be updated to describe the latest language changes. Whenever I find some time, I update some of them to be up-to-date, but this isn't easy as the language is rapidly evolving. I apologise for any confusion caused by this.
let
is indeed a valid way to declare new variables. In fact, all of the below lines are correct and have the exact same semantics:
let newValue = i + 1
let newValue: int = i + 1
final var newValue = i + 1
final var newValue: int = i + 1
int newValue = i + 1
final int newValue = i + 1
So is auto
no longer used?
It was deprecated in v0.18.0
. Seems like you can still kind of use it, but it will probably cause compiler errors in random places - so... don't do it. Will be removed in the next update.
It was deprecated over 12 versions ago and it hasn't been removed yet?
Why is final
a valid modifier for variables when let
exists?
That's a valid concern. The final
variable modifier is still there mainly for C-style declarations of the form Type name = expr
. They are deprecated in v0.32.0 and will be removed in the future, so it makes sense to disallow final var
in favor of let
. I will probably add a deprecation warning for the modifier in the next release.