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

[Bug] All global variable assignments should not go to __main__global_init #2573

Closed
Vipul-Cariappa opened this issue Mar 3, 2024 · 0 comments · Fixed by #2696
Closed

[Bug] All global variable assignments should not go to __main__global_init #2573

Vipul-Cariappa opened this issue Mar 3, 2024 · 0 comments · Fixed by #2696

Comments

@Vipul-Cariappa
Copy link
Contributor

I came across this bug while trying to debug #2457.

Look at the code and output of the two cases

Code:

l: list[i32] = [1, 2, 3, 4]
print("Before Pop:", l)
x: i32 = l.pop()
print("After Pop:", l)
print("Poped Element: ", x)

Output:

Before Pop: [1, 2, 3]
After Pop: [1, 2, 3]
Poped Element:  4

Code:

l: list[i32] = [1, 2, 3, 4]
print("Before Pop:", l)
l.pop()
print("After Pop:", l)

Output:

Before Pop: [1, 2, 3, 4]
After Pop: [1, 2, 3]

This is happening because the line x: i32 = l.pop() is compiled into the __main__global_init function, but it should actually be compiled into __main__global_stmts. Because __main__global_init is called before __main__global_stmts.

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

Successfully merging a pull request may close this issue.

1 participant