Skip to content

Commit

Permalink
slightly tighten up the getindex case
Browse files Browse the repository at this point in the history
  • Loading branch information
nsajko committed Dec 24, 2024
1 parent 39fed7d commit d1bb027
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/generator_eltype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +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
if B <: Type
# a user may overload `getindex(user_type)` to return a non-`Vector` `AbstractVector`
Any
AbstractVector{h(B)}
elseif (eltype(A) == keytype(B)) || ((eltype(A) <: Integer) && (keytype(B) <: Integer))
valtype(B)
else
Expand Down
4 changes: 4 additions & 0 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ 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]),
Expand Down

0 comments on commit d1bb027

Please sign in to comment.