KY1 instance name equals classname

In KY1 tests, i get a testprogram:

class quz {
  inquz() {
    print "from quz";
  }
}

class hello < quz {
  inhello() {
    print "from hello";
  }
}

class bar < hello {
  inbar() {
    print "from bar";
  }
}

// bar should inherit the methods
// from both quz and hello
var bar = bar();
bar.inquz();
bar.inhello();
bar.inbar();

I dont think it should be possible that the instance name and the classname clash ?

The book doesnt mention anything explicit on the topic, but in the environment, everything is stored in a map indexed by name, so the instance definition will overwrite the class definition, thereby loosing all the class information.

Or am i missing something?

Thanks,

Kurt

Hey @InvalidName-pfft, the same scoping rules should apply here. Your implementation should support shadowing as well.

For context, our tester are validated against the official Lox, and you can try out the code in the Lox Playground to confirm the behavior.

You’re absolutely right. I was missing something.

Thanks also for pointing at the lox playground.

1 Like

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