I have an interface which exposes some functions, let’s call them
g here for the MWE.
The user is expected to define methods for user-defined types. But it is sufficient to define one of them, as the other can be derived. For some types, defining one is more natural than the other, but it varies by type, so there is no default ordering.
I would like to provide an informative error message instead of a
StackOverflowError when the user fails to define either of the methods.
f(A, x) = g(A, x) + 1 g(A, x) = f(A, x) - 1
struct MyType end f(::MyType, x) = abs2(x)
and everything works out:
julia> f(MyType(), 1) 1 julia> g(MyType(), 1) 0
User forgets to define methods
julia> struct MyOtherType end julia> f(MyOtherType(), 1) ERROR: StackOverflowError: Stacktrace:  g(::MyOtherType, ::Int64) at ./REPL:1  f(::MyOtherType, ::Int64) at ./REPL:1 ... (the last 2 lines are repeated 39998 more times)  g(::MyOtherType, ::Int64) at ./REPL:1
I would like to detect this somehow and provide suggestions.