diff --git a/base/generator_eltype.jl b/base/generator_eltype.jl index 1207206c85aaf..7c544bf8d0291 100644 --- a/base/generator_eltype.jl +++ b/base/generator_eltype.jl @@ -3,15 +3,12 @@ function eltype(::Type{Generator{A, typeof(identity)}}) where {A} end function eltype(::Type{Generator{A, Fix1{typeof(getindex), B}}}) where {A, B} - function h(::Type{Type{T}}) where {T} - T - end - function h(::Type{<:Type}) - Any - end if B <: Type - # a user may overload `getindex(user_type)` to return a non-`Vector` `AbstractVector` - AbstractVector{h(B)} + # TODO: theoretically we could be more precise here and return a subtype + # of `AbstractVector`. The problem is that several packages do dubious + # punning of `getindex`. See + # https://github.com/mcabbott/AxisKeys.jl/issues/163 + Any elseif (eltype(A) == keytype(B)) || ((eltype(A) <: Integer) && (keytype(B) <: Integer)) valtype(B) else diff --git a/test/iterators.jl b/test/iterators.jl index d8b6eaca21f4f..dfa7763ac3c58 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -1016,10 +1016,6 @@ end end @testset "`eltype` for `Generator` involving `Fix` and `getindex`/`getfield` (issue #41519)" begin - @testset "special cases" begin - (f, i) = (Base.Fix1(getindex, Int), [3, 7]) - @test AbstractVector{Int} >: @inferred eltype(Iterators.map(f, i)) - end @testset "correct `eltype`" begin for (f, i) ∈ ( (Base.Fix1(getindex, Int), [3, 7]),