RequiredInterfaces.jl
RequiredInterfaces.jl copied to clipboard
Interfaces failing when matching on supertype
The following fails because I define bar(::Foo, ::Any), which gives an ambiguity error when I try e.g. bar(::Foo, ::Int) with the default error fallback using the abstract type
using RequiredInterfaces
abstract type MyInterface end
@required MyInterface begin
bar(::MyInterface, ::Number)
end
struct Foo <: MyInterface end
bar(::Foo, x) = x
RequiredInterfaces.check_implementations(MyInterface)
# Fails because of ambiguity with the erroring fallback
Yes, this is a limitation of having to create actual methods to make the fallback work :( It wouldn't be a problem if the typesystem itself were aware of the interface, because then the error would come from having a distinction between an interface & a defined method to throw the NotImplementedError from. It would be the compiler/type checker that throws the error, not a fallback method.
I think it could be made to work in this particular case, at least in terms of having check_implementations report a "success", but you'd still get an ambiguity when actually trying to call this method.