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

zero(Quantity{Int64, D, U} where U where D) should error? #264

Closed
goretkin opened this issue Aug 28, 2019 · 1 comment · Fixed by #266
Closed

zero(Quantity{Int64, D, U} where U where D) should error? #264

goretkin opened this issue Aug 28, 2019 · 1 comment · Fixed by #266

Comments

@goretkin
Copy link

goretkin commented Aug 28, 2019

julia> zero(Quantity{Int64, D, U} where U where D)
0

This happens via a fallback to

julia> convert(Quantity{Int64, D, U} where U where D, 0)
0

The convert behavior makes sense, since it returns a representation of 0 of type Quantity{Int64, D, U} where U where D. But I'm not sure what it means to return the zero element of a quantity whose units are not specified.

I came to this conclusion via JuliaLang/julia#33099 which, in my opinion, erroneously succeeds and should have instead failed under the fallback for zero.

ajkeller34 pushed a commit to rigetti/Unitful.jl that referenced this issue Sep 1, 2019
… specified. Closes PainterQubits#264.

- `zero(::Type{<:AbstractQuantity{T}}) where T` should fail.
- `zero(::Type{<:AbstractQuantity{T,D}}) where {T,D}` should use `upreferred(D)`.
@ajkeller34
Copy link
Collaborator

I think this should be fixed now—I also implemented behavior for types like Quantity{Int64, 𝐋}.

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