Skip to content

Inadequate support of promote_rule for non-concrete types #343

Description

@kimikage

For better or worse, PR #207 is the most significant change in FPN v0.9.
However the current promote_rule for non-concrete types is somewhat imperfect.
In ColorTypes.jl, I am keenly aware that the handling of non-concrete types can lead to chaos.
Here, I’d like to think about ways to make things a little better, as long as they don’t go against common sense.

julia> promote_rule(Normed{UInt8, 8}, Fixed{Int8, 7})
Float32

julia> promote_rule(Normed{UInt8}, Fixed{Int8})
Union{} # -> Float32

julia> promote_rule(Normed{UInt8}, Normed{UInt8})
Union{} # -> Normed{UInt8}

julia> promote_rule(Normed{UInt8}, Normed{UInt16})
Union{} # -> Normed{UInt16}

julia> promote_rule(Normed{UInt8}, Normed)
Union{} # -> Normed

julia> promote_rule(Normed{UInt8}, Normed{Union{UInt8, UInt16}})
Union{} # -> Normed (Any desire to make this more strict is a path to despair.)

julia> promote_rule(Normed{UInt8}, FixedPoint)
Union{} # -> FixedPoint

julia> promote_rule(Normed{UInt8}, Float64)
Float64

julia> promote_rule(Normed, Float64)
ERROR: StackOverflowError # -> BigFloat

julia> promote_rule(Normed{UInt8}, Int8)
Float32

julia> promote_rule(Normed, Int8)
Normed # -> BigFloat

Some of the unnatural promotions or stack overflow errors are caused by issue #342. In other words, fixing issue #342 will resolve some of these issues.

Activity

  1. changed the title [-]`promote_rule` for non-concrete types[/-] [+]Inadequate support of `promote_rule` for non-concrete types[/+] on Sep 29, 2026
  2. kimikage commented on Sep 29, 2026

    @kimikage
    CollaboratorAuthor

    This is planned to be fixed in PR #341. However, since the impact is greater than originally anticipated, I will split the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions