f18 icon indicating copy to clipboard operation
f18 copied to clipboard

Invalid "CYCLE construct-name is not in scope" error in label-do-stmt

Open jeanPerier opened this issue 5 years ago • 1 comments

The following code raises error: CYCLE construct-name is not in scope when it should not.

  mainloop : do 1 i=1,100
        cycle mainloop
1 end do mainloop
  end

The issue lies in the way construct-name are checked in CheckLabelContext in lib/semantic/resolve-labels.cc. label-do-stmt are not handle as constructs in the parse tree, hence, associated construct-name is not pushed in the constructNames_ data structure. Adding the construct-name when meeting a label-do-stmt is easy, but removing it when leaving the loop is harder.

  • Proposal fix 1: move these checks after label-do-stmt have been rewritten to non-label-do-loops.

  • Proposal fix 2: in resolve-labels.cc, ParseTreeAnalyzer visitor, push the construct-name when meeting a label-do-stmt and check every target label against the current active label-do-stmts and pop associated construct-name if relevant.

jeanPerier avatar Jul 10 '19 15:07 jeanPerier

The checking of construct names could be moved to resolve-names.cc. That has to recognize when construct names are defined anyway because they can't conflict with other names. So it would be a matter of moving the code that maintains the constructNames_ stack and checks the end names.

An alternative would be to move that code into a new Checker. That has the benefit of making resolve-labels.cc simpler without adding more complexity to resolve-names.cc.

tskeith avatar Jul 23 '19 23:07 tskeith