-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Lock type via := declaration #44259
Comments
Just if people search for it: implicit type annotation. |
That seems pretty clever/useful. One thing to think about is that currently you're not allowed to have multiple type declarations, regardless of the scope of the variable in a function, i.e.: function foo()
x::Int = 0
for _ = 1:10
x::Float64 = _ / 10
end
return x
end
ERROR: syntax: multiple type declarations for "x"
Stacktrace:
[1] top-level scope
@ REPL[6]:1 I mention that because I could see that being a confusing error if I had the same variable name in different scopes within a function, even if the desired type declarations are the same. |
Good point. I am in favor of keeping that restriction, though, even if the annotation is for the same type. I personally like it a lot if the compiler gives me hints, and this is a very clear error message. To me, more than one type annotation hints at a potential code smell, even if it's the same type. The syntax |
I would like to suggest
as a shortcut for
The same idea but with different syntax had already been proposed in #43671 (comment).
The text was updated successfully, but these errors were encountered: