f18
f18 copied to clipboard
Invalid "CYCLE construct-name is not in scope" error in label-do-stmt
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.
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
.