@code_warntype: assigning variable to array

Perhaps I’m being naive, but why is it for this simple example that @code_warntype suggests the variable c is of type Any in Julia 0.6 (pre-beta & master), when it is able to infer the correct type on Julia 0.5.1?

It seems far too basic.

Julia 0.6:

julia> function test(a)
       c=a
       end
test (generic function with 1 method)

julia> a=Vector{Int}(0) # or any simple array
0-element Array{Int64,1}

julia> @code_warntype test(a)
Variables:
  #self#::#test
  a::Array{Int64,1}
  c::Any

Body:
  begin 
      return a::Array{Int64,1}
  end::Array{Int64,1}

While in Julia 0.5.1:

julia> function test(a)
       c=a
       end
test (generic function with 1 method)

julia> a=Vector{Int}(0)
0-element Array{Int64,1}

julia> @code_warntype test(a)
Variables:
  #self#::#test
  a::Array{Int64,1}
  c::Array{Int64,1}

Body:
  begin 
      return a::Array{Int64,1}
  end::Array{Int64,1}

Help my curiosity… !
Thanks. :slight_smile:

Because c is not used, it’s inferred value does not matter. See https://github.com/JuliaLang/julia/issues/21281, https://github.com/JuliaLang/julia/issues/20801

2 Likes