Heuristic for checking if a Method always errors

@oxinabox mused here that it should be possible to use effect analysis to figure out if a method always, sometimes, or never errors.

I don’t know enough about the internals to dig into that at the moment, but it did lead me to wonder if there was a more basic heuristic I could use to at least tell if a method always errors.

I’m wondering if code_typed infers that the return type is Union{} does that guarantee that the function will error? Like this:

julia> err_f() = error("")
err_f (generic function with 1 method)

julia> code_typed(err_f, ()) |> only
CodeInfo(
1 ─     invoke Main.error(""::String)::Union{}
└──     unreachable
) => Union{}
1 Like

An empty union return type means that the function may not ever return a value, so it either runs infinitely or throws.

4 Likes