hope you are well. Probably you could help me out with an idea regarding baselang. In my InstanceMethod i have some strange behavior regarding variable scoping. I can reference MY_OBJECT_VAR before declaration.
This behavior applies both in the scenario with a NewExpression and in my own concept sql-block. I am using nothing special, just the common VariableReference.
I already experimented a bit. When using a self constructed VariableReference with the common inherited scope for VariableDeclaration, i can find the direct ancestor of some VarDecl also. I m just wondering. Shouldn’t the current VarDecl not be excluded from the scope? Is there some way for me to exclude the current VarDecl and use the inherited scope at the same time?
Of course, i tried chatgpt. While chatgpt understands MPS well, the answer was some pseudo code. I was not able to implement that idea … : )
JLS mandates that the scope for LocalVariableDeclaration starts in its own initializer. So we made LocalVariableDeclaration itself a ScopeProvider, and when the reference comes from its own initializer it explicitly adds this to the scope — mirroring Java, where int x = x; is in scope (just “might not be initialized”). So the inherited scope alone will keep re-adding the current declaration inside its own initializer no matter what your block does, because that provider sits below yours on the path.
I can’t think of a way your sql block could override that other than by constructing the entire scope by itself and never propagating to the parent scope or asking the containing StatementList for scope and bypassing the LocalVariable scope.