Skip to content

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

@adri09070

Description

@adri09070

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions