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

kind2 to-js generates definitions in alphabetic order #20

Open
mateusfccp opened this issue Jul 23, 2024 · 0 comments
Open

kind2 to-js generates definitions in alphabetic order #20

mateusfccp opened this issue Jul 23, 2024 · 0 comments

Comments

@mateusfccp
Copy link

mateusfccp commented Jul 23, 2024

Consider the following kind2 program:

// Unit/_.kind2
data Unit
| new

// Unit/new.kind2
new: Unit = ~λP λnew new

// Something/_.kind2
Something : * = Unit

// main.kind2
main: Something = Unit/new

Checking all the files results in no error.

After compiling the main file with kind2 to-js main, the result is the following:

const Something = Unit;
const Unit = null;
const Unit_new = (P_1) => (new_2) => new_2;
const main = Unit_new;

Because the identifiers are sorted alphabetically, const Something = Unit; comes before Unit is defined, which results in an error:

ReferenceError: Cannot access 'Unit' before initialization

Instead of sorting the identifier alphabetically, an alternative would to be sort them accordingly to the dependence tree, so that all dependencies are sorted before their dependents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant