-
-
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
restrict typed variable declaration to local x::T
and global x::T
#16071
Comments
Does this mean after the deprecation period we can make |
Yes, that is what it would mean. |
Seems like a good change. What should |
I think that can still be an implicit function f(x)
if x
T = Int
y::(println("HI");T) = 2.0
else
y = 3.0
end
y
end
f(false) (answer: it prints "HI" twice then throws "UndefVarError: T not defined") |
local x::T
and global x::T
local x::T
and global x::T
I think we should probably go all in and make type assertions on the left hand side of an assignment be an error. Or possibly a type assertion on the old value, but that seems bound to be confusing. Anyway, consider |
Syntax error suggesting |
I think this is a good idea. That example should be required to be written as: function f(x)
local y::Int
if x
y = 2.0
else
y = 3.0
end
return y
end |
I would rather remove |
The above PR is probably not the final word; it uses |
I'm strongly in favor of this. Just tracked down a latent bug in the for T in (Int32,Int64)
i::T, j::T = 1, 2
end sometimes meaning (and doing) something completely different for In observation, since the |
can I nominate this deprecation in 0.5 (and volunteer myself to work on it now)? (or at least the non-breaking part that in |
If you want to finish this before we feature freeze I'd be okay with it. I'm not okay with putting a patch I haven't seen yet on the milestone right now. |
Can you explain this a little more, @vtjnash? |
…local variable and fix a bug in env.jl where a typeassert was intended ref #16071
Sometimes |
What about type annotations in loops and function arguments? In 0.4, the former is a type declaration, but the latter is not ( |
Those already seem consistent to me (and unchanged from 0.4). Am I missing something?
|
You're right, I wasn't thinking of the loop as an assignment, but it makes perfect sense. |
…local variable and fix a bug in env.jl where a typeassert was intended ref #16071
…local variable and fix a bug in env.jl where a typeassert was intended ref #16071
deprecate `x::T` as type declaration syntax, ref #16071 deprecate `x::T = 0` where x is global and `global x::T` meaning typeassert, ref #964 also fix a bug where a typeassert was considered to be effect-free, causing it to be quasi-converted into a local variable declaration fix a bug in env.jl where a typeassert was intended
Fixed by #17445 |
deprecate `x::T` as type declaration syntax, ref JuliaLang#16071 deprecate `x::T = 0` where x is global and `global x::T` meaning typeassert, ref JuliaLang#964 also fix a bug where a typeassert was considered to be effect-free, causing it to be quasi-converted into a local variable declaration fix a bug in env.jl where a typeassert was intended
It's confusing that
x::T
is an assertion in some contexts and a declaration thatx
is a local variable of typeT
in other contexts. I propose we ultimately require a declaration keyword for the typed variable declaration usage, i.e.local x::T
orglobal x::T
. The first step is to deprecate the keywordless syntax, which should be done as soon as possible if we're going to do this.The text was updated successfully, but these errors were encountered: