Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This proposal adds inheritance to classes, following this syntax: ``` // Abstract classes may not be instantiated, but // may have abstract methods and be extended. abstract class AbstractBaseClass { virtual fn CanBeOverridden[me: Self]() -> i32 { return me.data; } abstract fn PureVirtual[me: Self]() -> i32; fn Create(data: i32) -> partial Self { return {.data = data}; } protected var data: i32; } // Classes are final by default class FinalClass extends AbstractBaseClass { impl fn PureVirtual[me: Self]() -> i32 { return me.x; } fn Create(data: i32) -> Self { return {.base = AbstractBaseClass.Create(data), .x = 2 * data}; } private var x: i32; } // Can be instantiated and extended base class ExtensibleClass { // May optionally use partial types in factory functions protected fn CreateAsBase(data: i32) -> partial Self { ... } fn Create(data: i32) -> Self { ... } } ``` Co-authored-by: Chandler Carruth <chandlerc@gmail.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
- Loading branch information