# 类型推断在 `getindex` 里失效?

``````julia> a = [(1, 2) (3, 4)];

julia> a isa Array{T} where T <: Tuple, a isa Array{NTuple{N, E}} where {N, E}
(true, true)

julia> @code_warntype getindex.(a, 1)
MethodInstance for (::var"##dotfunction#308#171")(::Matrix{Tuple{Int64, Int64}}, ::Int64)
from (::var"##dotfunction#308#171")(x1, x2) in Main
Arguments
#self#::Core.Const(var"##dotfunction#308#171"())
x1::Matrix{Tuple{Int64, Int64}}
x2::Int64
Body::Matrix{Int64}
│   %2 = Base.materialize(%1)::Matrix{Int64}
└──      return %2

julia> @code_warntype map(ele->ele[1], a)
MethodInstance for map(::var"#169#170", ::Matrix{Tuple{Int64, Int64}})
from map(f, A::AbstractArray) in Base at abstractarray.jl:2867
Arguments
#self#::Core.Const(map)
f::Core.Const(var"#169#170"())
A::Matrix{Tuple{Int64, Int64}}
Body::Matrix{Int64}
1 ─ %1 = Base.Generator(f, A)::Base.Generator{Matrix{Tuple{Int64, Int64}}, var"#169#170"}
│   %2 = Base.collect_similar(A, %1)::Matrix{Int64}
└──      return %2

``````

``````julia> b = [(1, 0.2) (3, 0.4)];

julia> b isa Array{T} where T <: Tuple, b isa Array{NTuple{N, E}} where {N, E}
(true, false)

julia> @code_warntype getindex.(b, 1)
MethodInstance for (::var"##dotfunction#309#172")(::Matrix{Tuple{Int64, Float64}}, ::Int64)
from (::var"##dotfunction#309#172")(x1, x2) in Main
Arguments
#self#::Core.Const(var"##dotfunction#309#172"())
x1::Matrix{Tuple{Int64, Float64}}
x2::Int64
Body::Union{Matrix{Float64}, Matrix{Int64}, Matrix{Real}}
│   %2 = Base.materialize(%1)::Union{Matrix{Float64}, Matrix{Int64}, Matrix{Real}}
└──      return %2

julia> @code_warntype map(ele->ele[1], b)
MethodInstance for map(::var"#173#174", ::Matrix{Tuple{Int64, Float64}})
from map(f, A::AbstractArray) in Base at abstractarray.jl:2867
Arguments
#self#::Core.Const(map)
f::Core.Const(var"#173#174"())
A::Matrix{Tuple{Int64, Float64}}
Body::Matrix{Int64}
1 ─ %1 = Base.Generator(f, A)::Base.Generator{Matrix{Tuple{Int64, Float64}}, var"#173#174"}
│   %2 = Base.collect_similar(A, %1)::Matrix{Int64}
└──      return %2

``````