Mysterious allocation in function returning Union type

I’m looking at functions with return type Union{T,Nothing} for some concrete type T. Most of the time they don’t allocate. But where does the allocation in f(a1, nothing) in the code below come from? Is there a way to avoid it while keeping the return type of f as a Union type?

struct A{T}
    x::T
end

f(a, b) = iszero(a.x) ? b : a
g(a, b) = iszero(a) ? b : a

a0 = A([0,0])
a1 = A([1,1])
c1 = A(1)
v1 = [1,1]

@ballocated f($a1, nothing)   # 16
@ballocated f($a0, nothing)   # 0
@ballocated f($a1, $a0)       # 0
@ballocated f($c1, nothing)   # 0
@ballocated g($v1, nothing)   # 0

I’m using Julia 1.8.2.

Note that if you remove the interpolation, the allocation goes back down to 0

@ballocated f(a1, nothing)   # 0 !!

Are you sure? On my machine, @ballocated f(a1, nothing) also gives 16.

Ah, you are right. I also defined a1 as a const-type global:

a1::A{Vector{Int}} = A([1,1])

and then it went to 0