From 15b044b766fc4044a6793064016c21b6165f34b8 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 6 Dec 2023 09:54:20 -0500 Subject: [PATCH] Fix incorrect computation of return_type of `itr` (#287) * 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 --- src/collect.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collect.jl b/src/collect.jl index b5e9e710..bab99f3a 100644 --- a/src/collect.jl +++ b/src/collect.jl @@ -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