enochii / jlox

a tree-walk interpreter for lox
0 stars 0 forks source link

Support field access in method without preceding "this" #4

Closed enochii closed 3 years ago

enochii commented 3 years ago

I think this one is easy? just hack the current LoxInstance.set(). When a set is triggered, the field will be added to instEnv.

enochii commented 3 years ago

Actually you can see some conflicts between lexical scope and the rule of class field access. Here gives a snippet:

var str = "global";
class A{
    f() {
        println str;
    }
}

var a = A();
a.str = "instance field";

Maybe you can also read this Chinese blog in which I have some discussion about this problem.