Skip to content

Commit 330869f

Browse files
committed
Define unit(::Any)m unit(::Funciton) and add a type restriction to unit(::Type{Union{Missing,T}})
This is to resolve errors with uncluding units into FiniteDifferences.jl. See JuliaDiff/FiniteDifferences.jl#244 for details. Tests for Units.jl need to be updated, if this is to be accepted. The totalness of unit introduced via unit(::Ay) might be a bit controversial, but I don't think that should be a problem. In general, things don't have units. Only Numbers do. Closes JuliaPhysics#806.
1 parent c1a9b4e commit 330869f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ julia> unit(1.0) == NoUnits
139139
true
140140
```
141141
"""
142+
@inline unit(x::Any) = NoUnits # In general, things do not have units.
142143
@inline unit(x::Number) = NoUnits
143144
@inline unit(x::Type{T}) where {T <: Number} = NoUnits
144-
@inline unit(x::Type{Union{Missing, T}}) where T = unit(T)
145+
@inline unit(x::Function) = NoUnits # Functions do not have units. Function values might.
146+
@inline unit(x::Type{Union{Missing, T}}) where { T <: Number } = unit(T) # Type restriction required here for T, or might result in infinite recursion.
145147
@inline unit(x::Type{Missing}) = missing
146148
@inline unit(x::Missing) = missing
147149

0 commit comments

Comments
 (0)