kyleect / locks

A toy language branched from Lox to learn language implementation and tooling. Forked from loxcraft
https://kyleect.github.io/locks/#/docs
MIT License
0 stars 0 forks source link

Access modifiers on class fields/methods #23

Open kyleect opened 11 months ago

kyleect commented 11 months ago

private, public, protected

Example

class Parent {
  public let a = 123;
  let b = 456;
}

class Child extends Parent {
  public let b = 789;
}

let parent = Parent();
print parent.a; // out: 123
print parent.b // out: VisibilityError: field "b" on class "Parent" has a visibility of "private"

let child = Child();
print child.a; // out: 123
print child.b; // out: 789

parent.b = 1000; // out: VisibilityError: field "b" on class "Parent" has a visibility of "private"
child.c = 2000; // out: VisibilityError: field "c" on class "Child" has a visibility of "private"

Questions

kyleect commented 10 months ago

https://github.com/kyleect/locks/pull/103