proposal-first-class-protocols
proposal-first-class-protocols copied to clipboard
Inheritance of symbols from parent to child
I have some questions about this example:
protocol A { a; }
protocol B extends A { b; }
class C implements B {
[A.a]() {}
[B.b]() {}
}
In this example, implementing B seems to require referencing A. I was wondering if it made sense to copy over the properties of A to B:
protocol A { a; }
protocol B extends A { b; }
class C implements B {
[B.a]() {} // copy A.a to B.a
[B.b]() {}
}
If not, does that mean that B can also have it's own symbol named a?
protocol A { a; }
protocol B extends A { a; b; }
class C implements B {
[A.a]() {}
[B.a]() {}
[B.b]() {}
}
Or should that be an early error?
B can have its own symbol named a. Relatedly, it can also implement A.a for you (that will probably be a common pattern). I don't think any of this is an issue. I'll leave this open for a bit to see if I've missed anything.
But without redeclaring anything would the child protocol copy the symbols from the parent?
It seems natural to assume that this works because of the extends keyword:
protocol A { a; }
protocol B extends A { b; }
class C implements B {
[B.a]() {} // copy A.a to B.a
[B.b]() {}
}
@thejameskyle It would not copy the symbols. I can see how someone might make that assumption, but the relationship implied between B and A by extends is that, in order to implement B, one must also implement A. Would another keyword or symbol make this more clear?
I think another keyword would be a lot clearer. A synonym of "requires" rather than something that implies inheritance would be best I think
I think I would be surprised if the keyword was "extends" and it did not set up a [[Prototype]] chain.
protocol A { a; }
protocol B depends on A { b; }
or, to align with #24
protocol A { a; }
protocol B requires A { b; }
👍 for requires.