# \`@inferred\` check for a small \`Union\` without being specific about the types

**URL:** https://discourse.julialang.org/t/inferred-check-for-a-small-union-without-being-specific-about-the-types/93470
**Category:** General Usage
**Tags:** testing, inference, type-stability
**Created:** [January 24, 2023, 4:45pm UTC](https://discourse.julialang.org/t/inferred-check-for-a-small-union-without-being-specific-about-the-types/93470 "2023-01-24T16:45:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [January 24, 2023, 4:45pm UTC](https://discourse.julialang.org/t/inferred-check-for-a-small-union-without-being-specific-about-the-types/93470/1 "2023-01-24T16:45:31Z")

</div>

Suppose I have a function

```julia
f(x) = x > 1 ? 0 : x

```

For this, I obtain

```julia
julia> @code_warntype f(0.2)
MethodInstance for f(::Float64)
  from f(x) @ Main REPL[43]:1
Arguments
  #self#::Core.Const(f)
  x::Float64
Body::Union{Float64, Int64}

```

Now, I want to write an inference unit test, but without being specific about the types in the union. I know that this works:

```julia
julia> @inferred Union{Float64,Int} f(0.2)
0.2

```

I would like to write something like

```julia
@inferred (Union{A,B} where {A,B}) f(0.2)

```

with the additional constraint, that `A` and `B` are concretely inferred. I wonder if there’s a way to test for that the inferred type is a small union, without specifying the exact types that are to be returned?

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [January 24, 2023, 8:55pm UTC](https://discourse.julialang.org/t/inferred-check-for-a-small-union-without-being-specific-about-the-types/93470/2 "2023-01-24T20:55:23Z")

</div>

Does `Union{<:Any,<:Any}` work?

```julia-repl
julia> @inferred Union{<:Any,<:Any} iterate(1:10)
(1, 1)

```
