Interpreter #FB4: test is bugged

On stage FB4 of the interpreter, one of the test seems bugged. Here is the output I got:

remote: [tester::#FB4] [test-4.lox] // This program tests that when a variable is declared in an outer scope,
remote: [tester::#FB4] [test-4.lox] // it can be used in an inner scope
remote: [tester::#FB4] [test-4.lox] // But when a variable is declared in an inner scope,
remote: [tester::#FB4] [test-4.lox] // it can't be used in an outer scope
remote: [tester::#FB4] [test-4.lox] {
remote: [tester::#FB4] [test-4.lox]   var quz = "outer quz";
remote: [tester::#FB4] [test-4.lox]   var bar = "outer bar";
remote: [tester::#FB4] [test-4.lox]   {
remote: [tester::#FB4] [test-4.lox]     quz = "modified quz";
remote: [tester::#FB4] [test-4.lox]     var bar = "inner bar";
remote: [tester::#FB4] [test-4.lox]     print quz;
remote: [tester::#FB4] [test-4.lox]     print bar;
remote: [tester::#FB4] [test-4.lox]   }
remote: [tester::#FB4] [test-4.lox]   print quz;
remote: [tester::#FB4] [test-4.lox]   print bar;
remote: [tester::#FB4] [test-4.lox] }
remote: [tester::#FB4] [test-4.lox] print bar;
remote: [tester::#FB4] [test-4.lox]
remote: [tester::#FB4] [test-4] $ ./your_program.sh run test.lox
remote: [your_program] modified quz
remote: [your_program] inner bar
remote: [your_program] modified quz
remote: [your_program] outer bar
remote: [your_program] Undefined variable 'bar'.
remote: [your_program] [line 17]
remote: [tester::#FB4] [test-4] ✓ modified quz
remote: [tester::#FB4] [test-4] ✓ inner bar
remote: [tester::#FB4] [test-4] ✓ modified quz
remote: [tester::#FB4] [test-4] ✓ outer bar
remote: [tester::#FB4] [test-4] ! Undefined variable 'bar'.
remote: [tester::#FB4] [test-4] Expected last stdout line to be "outer bar", but found extra line: "Undefined variable 'bar'."
remote: [tester::#FB4] [test-4] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

The print bar; on the last line should be an error and not print "outer bar" because it is defined in a nested scope, not at top level.

Hey @vsiles, sorry the error message is a bit confusing.

The tester is actually behaving correctly. It expects outer bar to be the last line of stdout, meaning nothing should come after it.

However, it’s receiving an extra line in stdout: Undefined variable 'bar'..

Fix: Print Undefined variable 'bar'. to stderr instead of stdout.

We’re also tweaking the error message in this PR.

Oh I see. Thank you for the clarification !

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.