@@ -191,7 +191,11 @@ A constant tuple of the existing abstract quantity types,
191191each as a tuple with (1) the abstract type,
192192(2) the base type, and (3) the default exported concrete type.
193193"""
194- const ABSTRACT_QUANTITY_TYPES = ((AbstractQuantity, Number, Quantity), (AbstractGenericQuantity, Any, GenericQuantity), (AbstractRealQuantity, Real, RealQuantity))
194+ const ABSTRACT_QUANTITY_TYPES = (
195+ (AbstractQuantity, Number, Quantity),
196+ (AbstractGenericQuantity, Any, GenericQuantity),
197+ (AbstractRealQuantity, Real, RealQuantity)
198+ )
195199
196200"""
197201 promote_quantity(::Type{<:UnionAbstractQuantity}, t::Type{<:Any})
@@ -202,7 +206,7 @@ If the current quantity type can already accommodate `t`, then the current type
202206promote_quantity (:: Type{<:Union{GenericQuantity,Quantity,RealQuantity}} , :: Type{<:Any} ) = GenericQuantity
203207promote_quantity (:: Type{<:Union{Quantity,RealQuantity}} , :: Type{<:Number} ) = Quantity
204208promote_quantity (:: Type{<:RealQuantity} , :: Type{<:Real} ) = RealQuantity
205- promote_quantity (T, _) = t
209+ promote_quantity (T, _) = T
206210
207211for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES
208212 @eval begin
222226
223227const DEFAULT_QUANTITY_TYPE = RealQuantity{DEFAULT_VALUE_TYPE, DEFAULT_DIM_TYPE}
224228
225- new_dimensions (:: Type{D} , dims... ) where {D<: AbstractDimensions } = constructorof (D)(dims... )
226- new_quantity (:: Type{Q} , l, r) where {Q<: UnionAbstractQuantity } = constructorof (Q)(l, r)
229+ @inline function new_dimensions (:: Type{D} , dims... ) where {D<: AbstractDimensions }
230+ return constructorof (D)(dims... )
231+ end
232+ @inline function new_quantity (:: Type{Q} , val, dims) where {Q<: UnionAbstractQuantity }
233+ Qout = promote_quantity (Q, typeof (val))
234+ return constructorof (Qout)(val, dims)
235+ end
227236
228237dim_type (:: Type{Q} ) where {T,D<: AbstractDimensions ,Q<: UnionAbstractQuantity{T,D} } = D
229238dim_type (:: Type{<:UnionAbstractQuantity} ) = DEFAULT_DIM_TYPE
0 commit comments