Skip to content

Inheritance of symbols from parent to child #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jamiebuilds opened this issue Oct 2, 2017 · 7 comments
Open

Inheritance of symbols from parent to child #23

jamiebuilds opened this issue Oct 2, 2017 · 7 comments

Comments

@jamiebuilds
Copy link
Member

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?

@michaelficarra
Copy link
Member

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.

@jamiebuilds
Copy link
Member Author

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]() {}
}

@michaelficarra
Copy link
Member

@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?

@jamiebuilds
Copy link
Member Author

I think another keyword would be a lot clearer. A synonym of "requires" rather than something that implies inheritance would be best I think

@ljharb
Copy link
Member

ljharb commented Oct 3, 2017

I think I would be surprised if the keyword was "extends" and it did not set up a [[Prototype]] chain.

@michaelficarra
Copy link
Member

protocol A { a; }
protocol B depends on A { b; }

or, to align with #24

protocol A { a; }
protocol B requires A { b; }

@Qard
Copy link

Qard commented Nov 8, 2017

👍 for requires.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants