Open apblack opened 6 years ago
What ought to happen is that the lhs of all of the declarations are processed before the rhs of any of them. Not clear how to do this in a visitor!
which is why I didn't do it in a visitor. Evaluating anything that can hold declarations (methods, blocks, objects, etc) must be done in two steps: first build the declarations into the context, second evaluate their values. That's two mutually recursive methods, so presumably two mutually recursive visitors.
That's two mutually recursive methods
No, just two passes at compile time; first build the symbol tables, and then check for shadowing. I don't know why I didn't see this before; it's another example of not understanding how to do something until after you have done it.
@Kim entered a duplicate of this as #260. That issue contains a larger example.
This program
should report a shadowing error when method
foo
usessecret
as the name of its parameter. If the order of the declarations is reversed, the error is correctly reported:This bug occurs because the declarations are processed in the order written, and shadowing errors are detected when the declaration of a temp or a parameter is processed. What ought to happen is that the lhs of all of the declarations are processed before the rhs of any of them. Not clear how to do this in a visitor!
Perhaps the simplest thing is to defer shadowing error reporting until after the symbol table has been built.