Skip to content

Commit b9617a3

Browse files
committed
Fix promotion between UnspecifiedZero and Bool
1 parent 6fbfd76 commit b9617a3

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "UnspecifiedTypes"
22
uuid = "42b3faec-625b-4613-8ddc-352bf9672b8d"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.1.2"
4+
version = "0.1.3"
55

66
[compat]
77
julia = "1.10"

src/unspecifiedzero.jl

+6
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ Base.:-(::UnspecifiedZero) = UnspecifiedZero()
3535
Base.promote_rule(::Type{<:UnspecifiedZero}, t::Type) = t
3636
Base.promote_rule(::Type{<:UnspecifiedZero}, ::Type{<:UnspecifiedZero}) = UnspecifiedZero
3737
Base.promote_type(::Type{<:Complex{<:UnspecifiedZero}}, t::Type) = complex(t)
38+
39+
# Avoid circular definition in `Base.promote_type`, since
40+
# Base defines `promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T`.
41+
# I.e. normally numbers take precedence over `Bool`, but that
42+
# isn't the case for `UnspecifiedZero`.
43+
Base.promote_rule(::Type{Bool}, ::Type{<:UnspecifiedZero}) = Union{}

test/test_basics.jl

+5
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ using Test: @testset, @test
1313
@test x isa UnspecifiedZero
1414
@test x === UnspecifiedZero()
1515
end
16+
17+
# Normally, any number type takes precedence over
18+
# `Bool`, check this isn't the case with `UnspecifiedZero`.
19+
@test promote_type(UnspecifiedZero, Bool) === Bool
20+
@test promote_type(Bool, UnspecifiedZero) === Bool
1621
end

0 commit comments

Comments
 (0)