diff --git a/src/BaseType.jl b/src/BaseType.jl index b2189d4..2bbc2ef 100644 --- a/src/BaseType.jl +++ b/src/BaseType.jl @@ -20,9 +20,9 @@ For example, ] ``` """ -function base_numeric_type(::Type{T}) where {T} +@generated function base_numeric_type(::Type{T}) where {T} params = T isa UnionAll ? T.body.parameters : T.parameters - return isempty(params) ? T : first(params) + return isempty(params) ? :($T) : :($(first(params))) end base_numeric_type(x) = base_numeric_type(typeof(x)) diff --git a/test/unittests.jl b/test/unittests.jl index 1d70151..22fbe92 100644 --- a/test/unittests.jl +++ b/test/unittests.jl @@ -25,12 +25,8 @@ expected_type_pairs = [ for (x, y) in expected_type_pairs @eval @test base_numeric_type($x) == $y # Make sure compiler can inline it: - if VERSION >= v"1.10" - @eval @inferred $y base_numeric_type($x) - end + @eval @inferred $y base_numeric_type($x) end @test base_numeric_type(1.5DynamicQuantities.u"km/s") == base_numeric_type(typeof(1.5DynamicQuantities.u"km/s")) -if VERSION >= v"1.10" - @inferred base_numeric_type(1.5DynamicQuantities.u"km/s") -end +@inferred base_numeric_type(1.5DynamicQuantities.u"km/s")