Spec icon indicating copy to clipboard operation
Spec copied to clipboard

`SpCodePresenter>>#evaluate:onCompileError:onError:` does not take into account additional bindings when evaluating an expression

Open adri09070 opened this issue 1 year ago • 0 comments

When evaluating an expression, the code presenter does not consider the bindings of its interaction model:

SpCodePresenter>>#evaluate:onCompileError:onError:
    result := self interactionModel compiler
		            source: aString;
		            environment: self environment;
		            failBlock: [
			            self announcer announce:
					            (SpCodeEvaluationFailedAnnouncement newContent:
							             aString).
			            ^ compileErrorBlock value ];
		            evaluate.

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:

image

The problem appears because, in a code presenter, SpCodeSelectionCommand>>#evaluate:andDo: calls SpCodePresenter>>#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 calls SpCodePresenter>>#evaluate:onCompileError:onError: in the end...)

Proposed fix: I think we should just provide the bindings from the interaction model to the compiler:

SpCodePresenter>>#evaluate:onCompileError:onError:
     result := self interactionModel compiler
		            source: aString;
		            environment: self environment;
		            bindings: self interactionModel bindings;
		            failBlock: [
			            self announcer announce:
					            (SpCodeEvaluationFailedAnnouncement newContent:
							             aString).
			            ^ compileErrorBlock value ];
		            evaluate.

adri09070 avatar Jan 16 '24 14:01 adri09070