Closed adri09070 closed 4 months ago
@StevenCostiou
the compiler is setup with a "requestor", see SpCodeInteractionModel>>#compiler
compiler
"Provide a compiler set up on the current context/class/receiver"
^ self doItReceiver class compiler
context: self doItContext;
receiver: self doItReceiver;
requestor: self
This makes the compiler add a scope for the requestor, soo OpalCompiler>>#buildOuterScope
buildOuterScope
| newScope |
newScope := self semanticScope.
self needRequestorScope ifTrue: [
"the requestor is allowed to manage variables, the workspace is using it to auto-define vars"
newScope := (self compilationContext requestorScopeClass new
requestor: self requestor) outerScope: newScope].
self bindings ifNotNil: [
"if we passed additional bindings in, setup a scope here"
newScope := (OCExtraBindingScope new
bindings: self bindings) outerScope: newScope].
^newScope
So normally this should ask the requestor before the bindings.
I wonder why this does not work correctly in your case, maybe this is due to #needRequestorScope returning false?
This is exactly the cause, thanks
It's a shame that this is not documented somewhere
When evaluating an expression, the code presenter does not consider the bindings of its interaction model:
So, if an interaction model allows to add additional bindings, it leads to a popup because the variable is not recognized, even if the binding DOES exist in the interaction model:
The problem appears because, in a code presenter,
SpCodeSelectionCommand>>#evaluate:andDo:
callsSpCodePresenter>>#evaluate:onCompileError:onError:
which does not take into account additional bindings.*The problem DOES NOT appear in the playground though, and I can't figure out why because it does use additional bindings ... One lead that could be tracked is that it does not use the same command class (it overrides the context menu to use
StEvaluateCommand
instead, which still callsSpCodePresenter>>#evaluate:onCompileError:onError:
in the end...)Proposed fix: I think we should just provide the bindings from the interaction model to the compiler: