Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure TDZ #124

Open
kaleidawave opened this issue Mar 9, 2024 · 1 comment
Open

Closure TDZ #124

kaleidawave opened this issue Mar 9, 2024 · 1 comment
Assignees
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking context Contexts (root or environment) needs-investigation Further information is requested

Comments

@kaleidawave
Copy link
Owner

kaleidawave commented Mar 9, 2024

Current TDZ finding is solved for standard statements AND for functions (as well as all things function-like). (thanks to #69 these errors have positions!)

This works for conditional function calls

function get_x() {
  return x
}

if (Math.random() > 0.5) {
  // Emits a TDZ error 'Variable 'x' used before declaration'
  get_x()
}

let x = 5;

However as it turns out with closures, TDZ issues are non-deterministic on their reference

let obj = {};
function closure3() {
    obj.get_z = () => {
        return z
    };

    if (Math.random() > 0.5) {
        return;
    }

    let z = 0;
}

closure3();
return obj.get_z()

Half the time this leaks a reference that never gets declared. Somehow we want to catch this mistake.

Things to think about

  • How does this work with unknown conditional interruptions
    • Even if the error occurs 1% of the time (changing the above to Math.random() > 0.99). It needs to error
  • How does this work with unknown interruptions (calling poly functions, which are neither known to be pure or impure in relation to throw events).
  • How can this provide good errors
    • Purely raising at function calling sites doesn't benefit checking libraries
    • Maybe a warning can occur?

At some point I think this can't fully support JavaScript and instead sit in a local minimum

@kaleidawave kaleidawave added needs-investigation Further information is requested checking Issues around checking context Contexts (root or environment) labels Mar 9, 2024
@kaleidawave kaleidawave self-assigned this Mar 9, 2024
@kaleidawave
Copy link
Owner Author

Had some thoughts: Instead it will be probably be solved the same way as find_possible_mutations. When a function is leaked outside the function it was defined it, it should run a similar Rust function to find_possible_mutations which checks any free_variables are defined. Thus avoiding any Event stuff

@kaleidawave kaleidawave added the blocking These issues are blocking the checker being used in projects label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking These issues are blocking the checker being used in projects checking Issues around checking context Contexts (root or environment) needs-investigation Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant