Problem
Ensuring a type fully implements a trait at compile time. We want compile time errors if a implementation drifts from a trait implementation.
A brief example -- say we have the following trait:
trait Writer {
writeByte: func(b: u8) : i32;
writeBytes: func(bytes: *u8, len: i32) : i32;
}
Then an implementation:
public struct StringBuffer {
...
}
public func (this: *StringBuffer) writeByte(b: u8) : i32 {
...
}
// Writer expects writeBytes instead of writeByteArray
public func (this: *StringBuffer) writeByteArray(bytes: *u8, len: i32) : i32 {
...
}
We won't know that StringBuffer doesn't fully implement the Writer trait until we try to assign it. Moreover, if the Writer trait evolves, we don't know StringBuffer no longer fully implements Writer trait.
Rough implementation idea
Create a new implements_traits note that defines a set of traits to be check if the implementation fully defines.
public @note implements_traits {
traits: []typeid
}
Then use it as so:
// would emit out a compile error if Writer or Reader traits
// were not FULLY implemented within this scope.
@implements_traits(.traits = []typeid {
typeof(:Writer),
typeof(:Reader),
})
public struct StringBuffer {
..
}
Outstanding questions:
- How would primitives use implements_traits?
- Given methods can be implemented in any module, the implements_traits check would only be valid for the scope of the module it's used in. This seems like a pretty heavy limitation
Problem
Ensuring a type fully implements a trait at compile time. We want compile time errors if a implementation drifts from a trait implementation.
A brief example -- say we have the following trait:
Then an implementation:
We won't know that
StringBufferdoesn't fully implement theWritertrait until we try to assign it. Moreover, if theWritertrait evolves, we don't knowStringBufferno longer fully implementsWritertrait.Rough implementation idea
Create a new
implements_traitsnote that defines a set of traits to be check if the implementation fully defines.Then use it as so:
Outstanding questions: