#DG2 test case 3 should not be a compilation error but runtime error

Tested in lox playground, for the test case 3, if the m(instance) call is commented out:

class Confused {
  method() {
    fun inner(instance) {
      var feeling = "confused";
      print this.feeling;
    }
    return inner;
  }
}

var instance = Confused();
var m = instance.method();
// m(instance);

lox will not throw an error and run successfully.

If we add a print before m(instance):

class Confused {
  method() {
    fun inner(instance) {
      var feeling = "confused";
      print this.feeling;
    }
    return inner;
  }
}

var instance = Confused();
var m = instance.method();
print 123;
m(instance);

lox would parse it successfully and run it as well, and 123 would print in console, not shown in the page.

So it should be a runtime error instead of compilation error. And it’s not a good idea to track binding properties on an object during parse stage of a dynamic language.

Hey @Arichy, thanks for highlighting the issue! I’ll check with the team and get back to you once we’ve identified the best approach to a fix.

Sorry for the confusion! The tester’s behavior is actually correct.

The issue was with the instructions, which are addressed in this PR.

1 Like

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