Class inheritance#230
Conversation
Also introduce the `open` keyword to allow classes to explicitly opt into inheritance.
|
|
|
I like that inheritable classes must be prefixed by |
|
This looks pretty good, except that I think Java's step of using That aside, the reasoning for |
|
|
||
| The original class RFC states that class names are hoisted and so can be used before the class declaration has been evaluated. This is unchanged by this RFC, but carries with it a consequence that is important to call out: | ||
|
|
||
| Class declarations have effects at the top level. Therefore, a class cannot inherit from another class that occurs lexically after it within the module. |
There was a problem hiding this comment.
Again, going to mention this. Implicit hoisting is a hack and doesn't even work for 90% of the cases it would be useful for. Get rid of it.
| ## Summary | ||
|
|
||
| ```luau | ||
| open class Animal |
There was a problem hiding this comment.
Orthogonal to this RFC, but could we also have syntax for abstract methods? Using error("override me") as the implementation in the base class won't scale since that can error at runtime, but an abstract method can error during class prototyping.
There was a problem hiding this comment.
It's worth potentially also considering interfaces, and deciding on abstract vs interfaces vs both (both can be quite useful to have, but also potentially too much stuff going on depending on the desired design direction).
There was a problem hiding this comment.
an abstract keyword seems to be the best option personally.
Rendered
See #229 for the main discussion thread on classes as a whole.