Follow-up to #74, which noted that a constant read through a class method still crashed. With main(), these all segfault on main because home is initialized after auth:
const home = process.env.HOME ?? "/x"
class K { get(): string { return home } }
const auth = new K().get() // also K.get() (static), new K().v set in the constructor or a field initializer
function main() { console.log(auth) }The walk from #74 now follows class members as well as module functions:
- a static method call follows that method;
new C()follows the constructors and instance field initializers ofCand its ancestors (sosuper()is covered);- an instance method call follows that method in the receiver's class, its ancestors and its subclasses, since the call can run an inherited method or an override.
Functions called from methods and methods called from functions are followed through the same work list, so mixed chains and recursion work. Getters reached by property access aren't calls, so they aren't followed yet.
Also checked: inheritance, a subclass override behind a base-typed value, a field initializer, a constructor reached through super(), mutual recursion between methods, and the function chain from #74.
Tests: tests/run/const_init_through_methods.tov (output from scripts/tov2js.sh); it crashes without the change. cargo test: run (168), ui, async, npm and http pass; fetch fails the same way on main (Bun 1.4.2 here, #68).
@Jeccoman is attempting to deploy a commit to the Cap Software Inc Team on Vercel.
A member of the Team first needs to authorize it.