tk3369 / BinaryTraits.jl

Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
MIT License
53 stars 3 forks source link

Interface contracts should propagate to subtypes #30

Closed tk3369 closed 4 years ago

tk3369 commented 4 years ago

Consider this example:

@trait Fly
@implement CanFly by liftoff()

abstract type Bird end
struct Duck <: Bird end
struct Chicken <: Bird end

@assign Bird with Fly

Since I assigned the abstract type Bird with the Fly trait and the Fly trait requires an interface contract liftoff, I expect both Duck and Chicken to satisfy that contract. However:

julia> check(Duck)
✅ Duck has no interface contract requirements.

The interface check should traverse super-type tree and check all required contracts.

KlausC commented 4 years ago

Yes, I was missing that, too. I think it is easy to change that in check by additionally checking all supertypes of Duck (except Any - we should also disallow to assign an interface to Any). In the case we support also parameter types, we must extend the checks to UnionAll