Composite Type Registering as Any with @code_warntype


#1

When I pass a composite type into a function, it doesn’t seem to know the element type even if it is explicitly defined. Should Julia be able to infer the type?

type TEST
  Notes::AbstractArray{Float64}
  Time::Float64
end
function foo(test::TEST)
  tempvar1 = test.Notes[1]
  tempvar2 = tempvar1*2. + test.Time
end
Variables:
  #self#::#foo
  test::TEST
  tempvar1::Any
  tempvar2::Any

Body:
  begin
      tempvar1::Any = (Main.getindex)((Core.getfield)(test::TEST, :Notes)::AbstractArray{Float64,N} where N, 1)::Any # line 3:
      SSAValue(0) = ((tempvar1::Any * 2.0)::Any + (Core.getfield)(test::TEST, :Time)::Float64)::Any
      return SSAValue(0)
  end::Any

#2

No, getindex on AbstractArray{Float64} can return anything.


#3

Abstract fields in composite types let you down in so many ways.

Compare with say:

type TEST2{T<:AbstractArray{Float64}}
    Notes::T
    Time::Float64
end

#4

Thanks for the suggestion!

type TEST2 worked!

Variables:
  #self#::#foo
  test::TEST2{Array{Float64,1}}
  tempvar1::Float64
  tempvar2::Float64