diff --git a/src/FixedPointNumbers.jl b/src/FixedPointNumbers.jl index 3873dc7..65e6704 100644 --- a/src/FixedPointNumbers.jl +++ b/src/FixedPointNumbers.jl @@ -469,7 +469,9 @@ function _length(r::StepRange{<:FixedPoint}) end hasalias(::Type) = false -hasalias(::Type{X}) where {T<:NotBiggerThanInt64, f, X<:FixedPoint{T,f}} = f isa Int +function hasalias(::Type{X}) where {T<:NotBiggerThanInt64, f, X<:FixedPoint{T,f}} + isprimitivetype(T) && (f isa Int) +end # `alias_symbol` is used to define type aliases, so we need this before we # include "src/fixed.jl" / "src/normed.jl". @@ -623,15 +625,18 @@ scaledual(::Type{Tdual}, x::AbstractArray{T}) where {Tdual, T <: FixedPoint} = convert(Tdual, 1/rawone(T)), reinterpret(rawtype(T), x) @noinline function throw_converterror(::Type{X}, @nospecialize(x)) where X <: FixedPoint - nbits = bitwidth(rawtype(X)) io = IOBuffer() showtype(io, X) - print(io, " is ") - print(io, nbits == 8 ? "an " : "a ", nbits, "-bit type representing ") - print(io, nbits <= 16 ? string(2^nbits) : "2^$nbits", " values from ") - print(IOContext(io, :compact=>true), typemin(X), " to ") - print(IOContext(io, :compact=>true), typemax(X), "; ") - print(io, "cannot represent ", x) + T = rawtype(X) + if isprimitivetype(T) && !(X <: FixedPoint{Union{}}) # The latter is a hint for JET. + nbits = bitwidth(T) + print(io, " is ") + print(io, nbits == 8 ? "an " : "a ", nbits, "-bit type representing ") + print(io, nbits <= 16 ? string(2^nbits) : "2^$nbits", " values from ") + print(IOContext(io, :compact=>true), typemin(X), " to ") + print(IOContext(io, :compact=>true), typemax(X), ";") + end + print(io, " cannot represent ", x) throw(ArgumentError(String(take!(io)))) end diff --git a/test/fixed.jl b/test/fixed.jl index c12f130..4d4ba10 100644 --- a/test/fixed.jl +++ b/test/fixed.jl @@ -805,6 +805,9 @@ end show(iob, Fixed{Int128,64}(-1.2345e6)) @test String(take!(iob)) == "Fixed{Int128,$(SP)64}(-1.2345e6)" + FixedPointNumbers.showtype(iob, Fixed{Union{}, 7}) + @test String(take!(iob)) == "Fixed{Union{},$(SP)7}" + # TODO: remove this test show(iob, reinterpret(Fixed{Int8,8}, signed(0xaa))) @test String(take!(iob)) == "Fixed{Int8,$(SP)8}(-0.336)" diff --git a/test/normed.jl b/test/normed.jl index c9e5e4b..be01472 100644 --- a/test/normed.jl +++ b/test/normed.jl @@ -782,6 +782,9 @@ end show(iob, Normed{UInt128,64}(1.2345e6)) @test String(take!(iob)) == "Normed{UInt128,$(SP)64}(1.2345e6)" + + FixedPointNumbers.showtype(iob, Normed{Union{}, 8}) + @test String(take!(iob)) == "Normed{Union{},$(SP)8}" end @testset "summary" begin