Is a function considered type stable if it has a branch that can throw an exception? Here’s an example:
function foo(x::Int)
if x < 0
error("Oops.")
else
2x
end
end
@code_warntype
doesn’t seem to have a problem with it:
julia> @code_warntype foo(-3)
Variables
#self#::Core.Compiler.Const(foo, false)
x::Int64
Body::Int64
1 ─ %1 = (x < 0)::Bool
└── goto #3 if not %1
2 ─ Main.error("Oops.")
└── Core.Compiler.Const(:(return %3), false)
3 ┄ %5 = (2 * x)::Int64
└── return %5
Considering that any function called inside a branch could conceivably throw an exception, I suppose it would be bad if the possibility of an exception interfered with type inference…