# BZ4: tests conflict

**URL:** <https://forum.codecrafters.io/t/bz4-tests-conflict/7704>\
**Category:** Bug Reports\
**Tags:** challenge:interpreter\
**Created:** [March 27, 2025, 4:55pm UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704 "2025-03-27T16:55:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![unkcpz](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/unkcpz/32/8050_2.png) [@unkcpz](https://forum.codecrafters.io/u/unkcpz)\
**Post date:** [March 27, 2025, 4:55pm UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/1 "2025-03-27T16:55:57Z")

</div>

It seems two tests are conflict in BZ4, the inner local scope \> closure which captured when declare the function \> outer scope.

```auto
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

```

```auto
// 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)

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 27, 2025, 8:14pm UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/4 "2025-03-27T20:14:06Z")

</div>

Hey @unkcpz, thanks for highlighting this!

I’ll check in with the team and get back to you as soon as we have a fix.

---

<div class="post-metadata">

**Author:** ![unkcpz](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/unkcpz/32/8050_2.png) [@unkcpz](https://forum.codecrafters.io/u/unkcpz)\
**Post date:** [March 28, 2025, 1:47am UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/5 "2025-03-28T01:47:37Z")

</div>

Thanks!  
I actually make tests passed. I think there is a bit ambiguity about how to deal with the `var a=97;` before the function call.

If I understand correctly, this is a case in the challenge (where re-declaration should be an error) of the book. To make it more similar to the book (such as [craftinginterpreters/test/closure/assign\_to\_closure.lox at 4a840f70f69c6ddd17cfef4f6964f8e1bcd8c3d4 · munificent/craftinginterpreters · GitHub](https://github.com/munificent/craftinginterpreters/blob/4a840f70f69c6ddd17cfef4f6964f8e1bcd8c3d4/test/closure/assign_to_closure.lox)), I think it should be:

```auto
var a = 63;

fun printAndModify() {
  print a;
  var a = 58;
  print a;
}

print a;
a = 97;
printAndModify();

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [March 29, 2025, 6:06pm UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/6 "2025-03-29T18:06:54Z")

</div>

Quick update: we’ve made a minor QoL fix in [this PR](https://github.com/codecrafters-io/interpreter-tester/pull/78).

---

<div class="post-metadata">

**Author:** ![unkcpz](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/unkcpz/32/8050_2.png) [@unkcpz](https://forum.codecrafters.io/u/unkcpz)\
**Post date:** [March 30, 2025, 1:43am UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/8 "2025-03-30T01:43:24Z")

</div>

Thanks for quick fix.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 6, 2025, 1:44am UTC](https://forum.codecrafters.io/t/bz4-tests-conflict/7704/9 "2025-04-06T01:44:21Z")

</div>

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