From d1bb027c5b4e400213b97fe3f490d3e7e9790ca4 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 24 Dec 2024 05:27:39 +0100 Subject: [PATCH] slightly tighten up the `getindex` case --- base/generator_eltype.jl | 5 ++++- test/iterators.jl | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base/generator_eltype.jl b/base/generator_eltype.jl index 24614f00e24cb..13b8ecb1eefc0 100644 --- a/base/generator_eltype.jl +++ b/base/generator_eltype.jl @@ -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 diff --git a/test/iterators.jl b/test/iterators.jl index dfa7763ac3c58..d8b6eaca21f4f 100644 --- a/test/iterators.jl +++ b/test/iterators.jl @@ -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]),