munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
9.05k stars 1.06k forks source link

Classes executing functions multiple times #1183

Closed dxkyy closed 1 week ago

dxkyy commented 1 week ago

I just finished 12.7, and this code:

class Foo {
  init() {
    print this;
  }
}

var foo = Foo();

produces this result:

Foo instance
Foo instance

This happens with every type of function in a class. E.g:

class Test {
    hello() {
        print "hello!!";
    }
}

Test().hello();

->

hello!!
hello!!

What can I do to fix this? / What did I do wrong?

dxkyy commented 1 week ago

Oops, I just forgot to delete interpreter.executeBlock(declaration.body, environment); before return null; in LuxFunction.call()