Skip to content
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

Broadcasting error for array type Any on Julia 1.8.1 #557

Closed
jgreener64 opened this issue Sep 12, 2022 · 3 comments · Fixed by #568
Closed

Broadcasting error for array type Any on Julia 1.8.1 #557

jgreener64 opened this issue Sep 12, 2022 · 3 comments · Fixed by #568

Comments

@jgreener64
Copy link

I am using Unitful 1.11.0. The following works as expected on Julia 1.8.0:

using Unitful
[1.0u"m", 2.0u"m"] .+ 3.0u"m"
Any[1.0u"m", 2.0u"m"] .+ 3.0u"m"

However on Julia 1.8.1 the last line errors with

ERROR: + not defined for Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}
Stacktrace:
 [1] error(::String, ::String, ::Type)
   @ Base ./error.jl:44
 [2] no_op_err(name::String, T::Type)
   @ Base ./promotion.jl:462
 [3] +(x::Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, y::Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}})
   @ Base ./promotion.jl:463
 [4] _broadcast_getindex_evalf
   @ ./broadcast.jl:670 [inlined]
 [5] _broadcast_getindex
   @ ./broadcast.jl:643 [inlined]
 [6] getindex
   @ ./broadcast.jl:597 [inlined]
 [7] copy
   @ ./broadcast.jl:899 [inlined]
 [8] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(+), Tuple{Vector{Any}, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}})
   @ Base.Broadcast ./broadcast.jl:860
 [9] top-level scope
   @ REPL[3]:1
@sostock
Copy link
Collaborator

sostock commented Sep 12, 2022

This looks like a Julia bug. In the case of the Vector{Any}, Julia 1.8.1 uses the method

+(x::T, y::T) where T<:Number in Base at promotion.jl:463

instead of the correct

+(x::AbstractQuantity{S,D,U}, y::AbstractQuantity{T,D,U}) where {S,T,D,U} in Unitful at quantities.jl:125.

Adding a +(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T,D,U} method would work around this, but only for Quantitys (not all AbstractQuantitys, for each of which a similar method would have to be added).

@sostock
Copy link
Collaborator

sostock commented Sep 17, 2022

This is now fixed on Julia master (#46722). When 1.8.2 is released, I will add a test to make sure it doesn’t regress.

@jgreener64
Copy link
Author

Great, thanks for the info.

sostock added a commit to sostock/Unitful.jl that referenced this issue Oct 2, 2022
sostock added a commit that referenced this issue Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants