-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pairwise for type-unstable corner case function #772
Conversation
`promote_type` is not a completely correct way of computing an upper bound for the return eltype. Use the same strategy as `map` and `broadcast` in Base instead, but with `promote_eltype` rather than `promote_typejoin`. We can still use `typejoin_union_tuple` since promotion does not happen inside tuple types. On Julia versions before 1.6 we would have to copy the full definition of `typejoin_union_tuple`, which is quite complex, so instead fall back to inferring eltype `Any` (inference wasn't so good anyway on these versions).
src/pairwise.jl
Outdated
end | ||
end | ||
else | ||
promote_type_union(::Type) = Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to be that defensive? If passed type is not a union then I guess we can return it - right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Actually the only case that would be hard to support is Tuple
types. I've refactored the code to improve this.
elseif T <: Tuple | ||
return typejoin_union_tuple(T) | ||
else | ||
return T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is line 148 covered in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's covered as promote_type_union
calls itself recursively, but I've added two tests for clarity.
promote_type
is not a completely correct way of computing an upper bound for the return eltype. Use the same strategy asmap
andbroadcast
in Base instead (JuliaLang/julia#30485), but withpromote_eltype
rather thanpromote_typejoin
. We can still usetypejoin_union_tuple
since promotion does not happen inside tuple types.On Julia versions before 1.6 we would have to copy the full definition of
typejoin_union_tuple
, which is quite complex, so instead fall back to inferring eltypeAny
(inference wasn't so good anyway on these versions).Fixes #771.