kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.44k stars 45 forks source link

Type checking recursive/cyclic functions #29

Open kaleidawave opened 1 year ago

kaleidawave commented 1 year ago

Eventually want to support

function myRecusiveLoop(i, x) {
    if (i <= 0) {
        return x * 2;
    }
    console.log(i);
    myRecusiveLoop(i - 1)
}

This is one of the most complex type checking problems but is possible with the following

Feel free to comment any code examples you have that you want to work with Ezno's checking features

kaleidawave commented 9 months ago

Update: Added a catch for recursion (which would cause the stack overflow the checker) a while back

https://github.com/kaleidawave/ezno/blob/1aa77e2aabb9533fb4fe90fa1ac9aaa24136256b/checker/src/types/calling.rs#L502-L515

Again more work to do. Maybe the learnings of the unknowns iteration counts could help here?