Skip to content

Commit

Permalink
Fix incorrect computation of return_type of itr (#287)
Browse files Browse the repository at this point in the history
* Fix incorrect computation of return_type of `itr`

The `itr` return type was assumed to be always the same as the first
element. This is false for many objects, such as Tuple. Additionally,
it was using a private API (Core.Compiler and
Core.Compiler.return_type) which are not stable across versions of
Julia and may return weird and unpredictable answers. Switch to using
the API in Base for this.

* Update collect.jl
  • Loading branch information
vtjnash authored Dec 6, 2023
1 parent 3b38c22 commit 15b044b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/collect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function collect_structarray(itr; initializer = default_initializer)
end

function _collect_structarray(itr::T, ::Nothing, ax; initializer = default_initializer) where {T}
S = Core.Compiler.return_type(first, Tuple{T})
S = Base.@default_eltype itr
return initializer(S, something(ax, (Base.OneTo(0),)))
end

Expand Down

0 comments on commit 15b044b

Please sign in to comment.