feat: implement static methods as local variables in implicit class scope

Refactor the compiler to treat static methods as local variables defined in an implicit scope surrounding the class, eliminating the need for VM-level static method support. This changes `declareVariable` to use the previously consumed token, adds `declareNamedVariable` for explicit token consumption, and updates `parameterList` to use the new function. Adjusts VM bytecode ordering for `CODE_METHOD_INSTANCE` and `CODE_METHOD_STATIC` to pop the class before the function body. Adds comprehensive test coverage for static fields including closures, nested classes, default null values, instance method access, and error cases for field usage outside classes or in static methods.
This commit is contained in:
Bob Nystrom
2014-01-19 21:01:51 +00:00
parent 9d71e765c8
commit 7ad96755f4
15 changed files with 307 additions and 81 deletions
+4
View File
@@ -4,3 +4,7 @@ class Foo {
}
IO.print((new Foo).bar.baz) // expect: baz
// TODO: Test that "this" is the class when in a static method.
// (Or disallow "this" in statics? It's useful since statics are
// inherited.)