#PL3 - a test that failed for me despite passing the stage

var bar = 0;
var foo = (bar = (foo = 2)) + 1;
print bar;
print foo;

Because I failed to check variable declarations at runtime, my program output was

2
3

even though my code passed #PL3. I’ve since fixed my program so it outputs:

[line 2]: var foo = (bar = (foo = 2)) + 1;
                            ^^^

Runtime error: undefined variable 'foo'

In fact, any assignment of a global variable before its declaration doesn’t seem to be checked properly at the moment by the CodeCrafters tests, not just this weird same-declaration case.

Hey @yinchi sorry for the delayed response!

Since you’ve finished the Resolving and Binding extension, does Stage #de8 (Identifier Resolution) cover the problematic case you’ve encountered?

I think the check for this specific case actually occurs in #PT7 “Self Initialization”. It definitely is a large gap between #PL3 (“Assignment operation”) and #PT7 if you do the challenge extensions in the listed order!

I guess the case of checking for self-initialization of globals was deferred until we had working scopes and a resolver, since we would have to revisit the self-initialization problem anyway?

Yes, we follow the order as presented in the book, so the check for self-initialization comes a bit later.