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

Fix promotion between UnspecifiedZero and Bool #7

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "UnspecifiedTypes"
uuid = "42b3faec-625b-4613-8ddc-352bf9672b8d"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.1.2"
version = "0.1.3"

[compat]
julia = "1.10"
6 changes: 6 additions & 0 deletions src/unspecifiedzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ Base.:-(::UnspecifiedZero) = UnspecifiedZero()
Base.promote_rule(::Type{<:UnspecifiedZero}, t::Type) = t
Base.promote_rule(::Type{<:UnspecifiedZero}, ::Type{<:UnspecifiedZero}) = UnspecifiedZero
Base.promote_type(::Type{<:Complex{<:UnspecifiedZero}}, t::Type) = complex(t)

# Avoid circular definition in `Base.promote_type`, since
# Base defines `promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T`.
# I.e. normally numbers take precedence over `Bool`, but that
# isn't the case for `UnspecifiedZero`.
Base.promote_rule(::Type{Bool}, ::Type{<:UnspecifiedZero}) = Union{}
5 changes: 5 additions & 0 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ using Test: @testset, @test
@test x isa UnspecifiedZero
@test x === UnspecifiedZero()
end

# Normally, any number type takes precedence over
# `Bool`, check this isn't the case with `UnspecifiedZero`.
@test promote_type(UnspecifiedZero, Bool) === Bool
@test promote_type(Bool, UnspecifiedZero) === Bool
end
Loading