You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.:
functionfoo()
x::Int=0for _ =1:10
x::Float64= _ /10endreturn 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 x := 0 is used in mathematics as "define x to be equal to 0", and every variable should only be declared once. The syntax x = 0 feels more like "give zero the name x".
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: