Return type of powermod is always a Union?

Why is the return type of powermod always a Union{Int64, Int128, BigInt}? As a consequence the following simple code is type-unstable:

julia> function f(a, b, c)
          a = powermod(a, b, c)
          a % 2 - a
       end

julia> @code_warntype f(3, 4, 5)
MethodInstance for f(::Int64, ::Int64, ::Int64)
  from f(a, b, c) @ Main REPL[16]:1
Arguments
  #self#::Core.Const(f)
  a@_2::Int64
  b::Int64
  c::Int64
Locals
  a@_5::Union{Int128, Int64, BigInt}
Body::Any
1 ─      (a@_5 = a@_2)
│        (a@_5 = Main.powermod(a@_5::Int64, b, c))
│   %3 = (a@_5 % 2)::Union{Int128, Int64, BigInt}
│   %4 = (%3 - a@_5)::Any
└──      return %4 

Is it to account for overflowing?

1 Like

This is on 1.10, right? Good catch. PR incoming.

2 Likes