Skip to content

Commit d05a39b

Browse files
committed
Set haszero in special test for TypeWithoutZero
1 parent 63281a0 commit d05a39b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/dense.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ norm2(x::Union{Array{T},StridedVector{T}}) where {T<:BlasFloat} =
114114
Return whether a type `T` has a unique zero element defined using `zero(T)`.
115115
If a type `M` specializes `zero(M)`, it may also choose to set `haszero(M)` to `true`.
116116
By default, `haszero` is assumed to be `false`, in which case the zero elements
117-
are deduced from values rather than the type.
117+
are deduced from values rather than the type. In general, if a type defines `zero(::Type{MyType})`,
118+
it should also define `haszero(::Type{MyType}) = true`.
118119
119120
!!! note
120121
`haszero` is a conservative check that is used to dispatch to

test/special.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Random.seed!(1)
115115
struct TypeWithZero end
116116
Base.promote_rule(::Type{TypeWithoutZero}, ::Type{TypeWithZero}) = TypeWithZero
117117
Base.convert(::Type{TypeWithZero}, ::TypeWithoutZero) = TypeWithZero()
118+
LinearAlgebra.haszero(::Type{TypeWithoutZero}) = true
119+
LinearAlgebra.haszero(::Type{TypeWithZero}) = true
118120
Base.zero(x::Union{TypeWithoutZero, TypeWithZero}) = zero(typeof(x))
119121
Base.zero(::Type{<:Union{TypeWithoutZero, TypeWithZero}}) = TypeWithZero()
120122
LinearAlgebra.symmetric(::TypeWithoutZero, ::Symbol) = TypeWithoutZero()

0 commit comments

Comments
 (0)