@@ -190,11 +190,33 @@ private void buildBlocks(Method method) throws InvalidSpecCompileException {
190190 List <Statement > stats = AstUtil .getStatements (method .getAst ());
191191 Block currBlock = method .addBlock (new AnonymousBlock (method ));
192192
193+ String statementLabelToTransplant = null ;
193194 for (Statement stat : stats ) {
194- if (stat .getStatementLabel () == null )
195+ if (stat .getStatementLabel () == null ) {
196+ if (statementLabelToTransplant != null ) {
197+ stat .setStatementLabel (statementLabelToTransplant );
198+ }
195199 currBlock .getAst ().add (stat );
196- else
200+ } else {
197201 currBlock = addBlock (method , stat );
202+ }
203+ // Usually, you have a label on a statement like
204+ //
205+ // combined:
206+ // x << [1]
207+ //
208+ // and the label stays on that statement and could be used in later stages of the AST processing.
209+ // Especially for "combined" this is essential for proper operation.
210+ //
211+ // But if the label has a description like
212+ //
213+ // combined: 'combined with x'
214+ // x << [1]
215+ //
216+ // then the description is added as "text" to the current block and the whole statement is swallowed.
217+ // If the label is needed for further processing like for "combined", this is then missing,
218+ // so transplant the label to the following statement which it actually affects.
219+ statementLabelToTransplant = (getDescription (stat ) == null ) ? null : stat .getStatementLabel ();
198220 }
199221
200222 checkIsValidSuccessor (method , BlockParseInfo .METHOD_END ,
@@ -215,7 +237,7 @@ private Block addBlock(Method method, Statement stat) throws InvalidSpecCompileE
215237 String label = stat .getStatementLabel ();
216238
217239 for (BlockParseInfo blockInfo : BlockParseInfo .values ()) {
218- if (!label .equals (blockInfo .toString ())) continue ;
240+ if (!label .equals (blockInfo .toString ())) continue ;
219241
220242 checkIsValidSuccessor (method , blockInfo , stat .getLineNumber (), stat .getColumnNumber ());
221243 Block block = blockInfo .addNewBlock (method );
@@ -226,9 +248,9 @@ private Block addBlock(Method method, Statement stat) throws InvalidSpecCompileE
226248 block .getDescriptions ().add (description );
227249
228250 return block ;
229- }
251+ }
230252
231- throw new InvalidSpecCompileException (stat , "Unrecognized block label: " + label );
253+ throw new InvalidSpecCompileException (stat , "Unrecognized block label: " + label );
232254 }
233255
234256 private String getDescription (Statement stat ) {
0 commit comments