I noticed that Julia cannot infer the type of fields in user-defined types. Is that a bug or a feature?
struct MyType1{T<:Real}
x::Vector{T}
end
function foo{T<:Real}(y::MyType1{T})
a = y.x
end
yy = MyType1(zeros(5))
Then the type of yy.x
cannot be inferred.
julia> @code_warntype(foo(yy))
Variables:
#self#::#foo
y::MyType1{Float64}
a::ANY
Body:
begin
SSAValue(0) = (Core.getfield)(y::MyType1{Float64}, :x)::Array{Float64,1}
return SSAValue(0)
end::Array{Float64,1}
julia> versioninfo()
Julia Version 0.6.0-pre.beta.68
Commit e5e365c* (2017-04-07 18:50 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin15.5.0)
CPU: Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Penryn)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, penryn)
the same thing happens on latest master. It worked well on 0.5.