Seelengrab / RequiredInterfaces.jl

A small package for providing the minimal required method surface of a Julia API
https://seelengrab.github.io/RequiredInterfaces.jl/
MIT License
33 stars 0 forks source link

Interfaces failing when matching on supertype #18

Open SBuercklin opened 1 week ago

SBuercklin commented 1 week ago

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
Seelengrab commented 1 week ago

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.