openroberta-lab icon indicating copy to clipboard operation
openroberta-lab copied to clipboard

For loop variables can be used outside of its scope

Open heini208 opened this issue 3 years ago • 3 comments

Describe the bug

  • When using a for loop the counter variable wont stop you from generating and compiling code even if it's used outside of the loop it was created in
  • This causes compiler errors

To Reproduce Steps to reproduce the behavior:

  1. create a for loop
  2. use the variable of that loop outside of it
  3. see Warning
  4. generate code or compile
  5. see error

Expected behavior

  • There is a warning that you are using the variable wrong but the warning should a blocking error that stops you from generating wrong code

Screenshots image

heini208 avatar Jan 21 '22 14:01 heini208

@heini208, I'd like to request you to assign this issue to me.

infernus01 avatar Feb 05 '22 10:02 infernus01

Hi @heini208, please guide me on to how to recreate this issue and what packages/folders should I refer to?

infernus01 avatar Feb 10 '22 17:02 infernus01

@infernus01 sure let me first explain the issue again. The Problem ist not in the code-generation this works as expected however the program shown in the picture should not be able to be generated. If you visit the Open-Roberta-Lab and build the program obove on any robot system you can see that you get a warning once you put the variables block "set i to x" outside of the for loop.

The problem is warnings dont stop the code generation on the right (this icon: <>) to be openable, but in this case it totally should. So, to put it short a warning is displayed where actually an Error should be displayed similar to this: image

This is usually handled by a Visitor class in this case it should be the CommonNepoValidatorAndCollectorVisitor.java We have a method called addErrorToPhrase(Phrase, "ERROR_MSG"); which does exactly what we want.

This method should be called in visitVarDecleration() if the variable is a loop variable which is not inside its own loop.

PS: After looking into the issue a bit the warning comes from Blockly which is a library we use for all our Program blocks. You could first check if its possible to know wether or not the variable is outside of it's own loop, if that's the case we could remove the blockly warning afterwards.

heini208 avatar Feb 11 '22 13:02 heini208

related to #935

bjost2s avatar Dec 08 '22 09:12 bjost2s

Tested successfully on test server with the following program: EV3LoopVarsOutside.xml.txt

RaghuvirShirodkar avatar Mar 03 '23 07:03 RaghuvirShirodkar