-
Notifications
You must be signed in to change notification settings - Fork 152
Fix zero(SVector{3,Any}) etc. with multiple dispatch #1129
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
Conversation
|
I was thinking about going back to 1.5.12 behavior when we have |
|
@Jollywatt Do you have any thoughts on this? |
src/arraymath.jl
Outdated
| @inline fill(val, ::Type{SA}) where {SA <: StaticArray} = _fill(val, Size(SA), SA) | ||
| @generated function _fill(val::U, ::Size{s}, ::Type{SA}) where {U, s, SA <: StaticArray} | ||
| @inline fill(val, ::SA) where {SA <: StaticArray{<:Tuple}} = _fill(val, Size(SA), SA) | ||
| @inline fill(val::U, ::Type{SA}) where {SA <: StaticArray} where U = fill(val, SA{U}) |
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.
I don't pretend to know much about this code, but is it safe to add the type parameter U to SA{U} like that? (Line 38). What if SA = SVector{N,T} where {N,T} so that SA{U} = SVector{U,T} where T? Then the eltype U would be in the N slot instead of the T slot.
Would something like
@inline fill(val::U, ::Type{SA}) where {SA <: StaticArray{S}} where {U,S} = fill(val, SA{U})at least ensure that the first type parameter of SA is filled, so that SA{U} fills the second slot? But then what happens when SA = SVector{3,Float64} has no slots to be filled?
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.
I agree, applying U to an arbitrary subtype of StaticArray is not safe.
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.
Thanks for the comments! I have replaced SA{U} with Base.typeintersect(SA, AbstractArray{U}).
|
I think having Less correct would be to return a Definitely incorrect would be for TL;DR I agree with this PR. Thanks @hyrodium for taking the time to make it! |
This PR fixes the output values commented on #1122 (comment).
StaticArrays.jl v1.5.12
StaticArrays.jl v1.5.13
After this PR
I think the return value on v1.5.13 is problematic, but I'm not sure the return value on v1.5.12 is correct because
zero(Any)throws an error.