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

global variables don't work during chapter 11 #1176

Open
Xythium opened this issue Sep 23, 2024 · 0 comments
Open

global variables don't work during chapter 11 #1176

Xythium opened this issue Sep 23, 2024 · 0 comments

Comments

@Xythium
Copy link

Xythium commented Sep 23, 2024

is this intended behavior?

global variables get skipped in the resolver because there is no scope on the stack (in declare() and define())

when accessing a global variable in a new scope (function or loop for example) in visitVariableExpr(), there is a scope on the stack. so it will check if if the variable is defined, which it is not. scopes.peek().get(expr.name.lexeme) == Boolean.FALSE
it will then report a parse error Lox.error(expr.name, "Can't read local variable in its own initializer.");

is this intended during (and/or after) chapter 11? this for example does not work

var a = 0;

for (var i = 0; i < 10; i = i + 1) {
    print a;
}

and im getting these parse errors in my implementation for this example

[line 4] Error at 'a': Can't read local variable in its own initializer.
[line 3] Error at 'i': Can't read local variable in its own initializer.
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