-
-
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
Issue with type inference in comprehensions #17717
Comments
What if a is a const? |
@KristofferC setting |
This program: function f(n)
a = zeros(Int, 3)
@show [a[j] for j in 1:n]
b = zeros(Int, 3)
@show [b[j] for j in 1:n]
c = zeros(Int, 3)
@show [c[j] for j in 1:n]
end
f(0) outputs the following: [a[j] for j = 1:n] = Int64[]
[b[j] for j = 1:n] = Union{}[]
[c[j] for j = 1:n] = Union{}[] If you re-order it so that |
The behavior is exactly as described in NEWS. This was discussed very extensively. The available options are (1) the current behavior, (2) always return |
I don't understand how repeating the same pair of lines (aside from changing the variable name from Also---and perhaps a separate bug---I think |
looks like wat material to me.
I agree we should try to avoid the stack overflow there, perhaps a "deliberately unimplemented" MethodError. |
I am also quite perplexed by the behavior here. It looks like 3 identical uncoupled statements so type inference should give the same answer for all of them? |
This is why some of us argued for always returning |
But why is |
I agree it ideally shouldn't be, but it's probably the same problem as #15276. |
but on the second line the same specifier is still, sadly, necessary That these specifiers became necessary here was what led me to report JuliaLang/julia#17717 (comment) back when julia 0.5 was starting to stabilize (see bec87df).
In the discussion for #7258 it was proposed to make empty comprehensions return
Array{Union{},1}
, but the text of the relevantNEWS.md
entry suggests that this was ultimately rejected, if I understand correctly. ("If the result is empty, then type inference is still used to determine the element type," it says.) However, the final expression below seems to result in aArray{Union{},1}
, even though it should be possible to infer the type.In particular, this causes the following to blow up:
The text was updated successfully, but these errors were encountered: