pharo
pharo copied to clipboard
Possible issue when getting the #sourceNode for ConstantBlockClosure
Is it expected that this fails in Pharo 11/12 and works in Pharo 10?
blocks := OrderedCollection new.
(FBDExamples>>#exampleSimpleBlock) innerCompiledBlocksDo: [ :aBlock |
blocks add: aBlock ].
self assert: blocks first sourceNode sourceCode = '[1]'.
In Pharo 10 the returned source code is [1]
, while in Pharo 11/12 it is ^[1]
.
The node of the block is RBBlockNode
in Pharo 10 and RBReturnNode
in Pharo 11/12
To work in Pharo 11/12 we can send value to the sourceNode.
self assert: blocks first sourceNode value sourceCode = '[1]'.
I tracked this down to the bc-> AST mapping being wrong when the block is a constant block.
Next step is to fix that
The problem is that OCBytecodeToASTCache>>#generateForNode: does not add any entry for compiledBlocks
I think we have to analyse all pushes, find when a constant block ist pushend and add the mapping pc -> AST from that
Just as a side-note, CleanBlockClosure>>#doPrintOn:
gets the source node of a compiled block using self sourceNode value
instead of self sourceNode. For constant blocks
sourceNodereturns a
RBReturnNodeand sending
value` to that returns the correct node. This results in the source code actually being ok when printing it
We currently have a workaround implemented by Andrei. @chisandrei it can be interesting to share it here.
The workaround is just calling self compiledBlock ast value
instead of self compiledBlock ast
when handling a RBReturnNode
.
Thanks!