If you mean testing as in unit testing, Test
offers the @inferred
macro. If you mean testing as in checking what the return type will be before running g
, you can also do this, but not through any exported methods (so beware).
You can use Base._return_type
and Base.return_types
julia> Base.return_types(+, (Int, Float64))
1-element Array{Any,1}:
Float64
julia> Base._return_type(+, (Int, Float64))
Float64
The return type is only as stable as your functions and inputs though:
julia> Base.return_types(+, (Complex, Int))
2-element Array{Any,1}:
Complex{Int64}
Complex{_A} where _A