Skip to content

Commit

Permalink
Fix promotion between UnspecifiedZero and Bool (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 16, 2025
1 parent 6fbfd76 commit b1819d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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 <[email protected]> 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

0 comments on commit b1819d6

Please sign in to comment.