feat: prevent metaclass inheritance and disallow super in static methods
Remove the metaclass inheritance chain that mirrored the class hierarchy, instead always binding metaclasses directly to Class. This prevents static methods from being inherited by subclasses. Also add a compile-time error when `super` is used inside a static method, since it would always delegate to Class without useful effect. Update the `isInsideMethod` check to use `compiler->fields` instead of walking the parent chain for correctness. Add test cases for the new restrictions and remove the old test that verified static method inheritance.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static methodOnFoo { IO.print("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
Bar.methodOnFoo // expect runtime error: Receiver does not implement method 'methodOnFoo'.
|
||||
@@ -1,23 +0,0 @@
|
||||
class Foo {
|
||||
static methodOnFoo { IO.print("foo") }
|
||||
static method(a) { IO.print("foo") }
|
||||
static method(a, b, c) { IO.print("foo") }
|
||||
static override { IO.print("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
static methodOnBar { IO.print("bar") }
|
||||
static method(a, b) { IO.print("bar") }
|
||||
static method(a, b, c, d) { IO.print("bar") }
|
||||
static override { IO.print("bar") }
|
||||
}
|
||||
|
||||
Bar.methodOnFoo // expect: foo
|
||||
Bar.methodOnBar // expect: bar
|
||||
|
||||
// Methods with different arity do not shadow each other.
|
||||
Bar.method(1) // expect: foo
|
||||
Bar.method(1, 2) // expect: bar
|
||||
Bar.method(1, 2, 3) // expect: foo
|
||||
Bar.method(1, 2, 3, 4) // expect: bar
|
||||
Bar.override // expect: bar
|
||||
Reference in New Issue
Block a user