It seems two tests are conflict in BZ4, the inner local scope > closure which captured when declare the function > outer scope.
var x = 1;
var y = 2;
fun printBoth() {
if (x < y) {
print "x is less than y:";
print x;
print y;
} else {
print "x is not less than y:";
print x;
print y;
}
}
{
var x = 10;
{
var y = 20;
var i = 0;
while (i < 3) {
x = x + 1;
y = y - 1;
print "Local x: ";
print x;
print "Local y: ";
print y;
i = i + 1;
}
if (x > y) {
print "Local x > y";
}
printBoth();
}
}
if (x == 1 and y == 2) {
print "Globals unchanged:";
printBoth();
}
print --- output ---;
// Logs from your program will appear here!
// Local x:
// 11
// Local y:
// 19
// Local x:
// 12
// Local y:
// 18
// Local x:
// 13
// Local y:
// 17
// x is less than y:
// 1 // -> captured as closure
// 2
// Globals unchanged:
// x is less than y:
// 1
// 2
// This program demonstrates global and local variable shadowing in Lox.
var a = 63;
fun printAndModify() {
print a;
var a = 58;
print a;
}
print a;
var a = 97;
printAndModify();
// remote: [tester::#BZ4] [test-1] $ ./your_program.sh run test.lox
// remote: [your_program] Logs from your program will appear here!
// remote: [your_program] 63
// remote: [your_program] 63 // ?? -> 63 is caputured as closure when function declared I believe, same as example above
// remote: [your_program] 58
// remote: [tester::#BZ4] [test-1] ✓ 63
// remote: [tester::#BZ4] [test-1] 𐄂 63
// remote: [tester::#BZ4] [test-1] Expected line #2 on stdout to be "97", got "63"
// remote: [tester::#BZ4] [test-1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)