Skip to content

Commit e765e46

Browse files
nsajkoKristofferC
authored andcommitted
relax dispatch for the IteratorSize method for Generator (#58110)
Fixes #58109 (cherry picked from commit 805f85f)
1 parent 600efd6 commit e765e46

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

base/generator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ IteratorSize(::Type{Any}) = SizeUnknown()
9898

9999
IteratorSize(::Type{<:Tuple}) = HasLength()
100100
IteratorSize(::Type{<:AbstractArray{<:Any,N}}) where {N} = HasShape{N}()
101-
IteratorSize(::Type{Generator{I,F}}) where {I,F} = IteratorSize(I)
101+
IteratorSize(::Type{<:Generator{I}}) where {I} = (@isdefined I) ? IteratorSize(I) : SizeUnknown()
102102

103103
haslength(iter) = IteratorSize(iter) isa Union{HasShape, HasLength}
104104

test/iterators.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -978,11 +978,10 @@ end
978978
@test accumulate(+, (x^2 for x in 1:3); init=100) == [101, 105, 114]
979979
end
980980

981-
982-
@testset "Iterators.tail_if_any" begin
983-
@test Iterators.tail_if_any(()) == ()
984-
@test Iterators.tail_if_any((1, 2)) == (2,)
985-
@test Iterators.tail_if_any((1,)) == ()
981+
@testset "issue #58109" begin
982+
i = Iterators.map(identity, 3)
983+
j = Iterators.map(sqrt, 7)
984+
@test (@inferred Base.IteratorSize(i)) === @inferred Base.IteratorSize(eltype([i, j]))
986985
end
987986

988987
@testset "IteratorSize trait for zip" begin

0 commit comments

Comments
 (0)