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

Function names can cause infinite recursion

Open heini208 opened this issue 3 years ago • 1 comments

Describe the bug

  • Most robots generate a function like main() or run() in their code generation regardless of blocks used
  • The problem is these names are possible custom function names which will then cause infinite recursion in languages like python and errors in languages like java
  • e.g. you make a function named main() and use it in a robot using python your program would now look like this: EV3 example: image

In python inside run() the last main method would be used which is the normal main method which would then call run which would then call main again causing an infinite loop and the custom function to be ignored

To Reproduce Steps to reproduce the behavior:

  1. create a program that uses a function called main() or run() in any robot generating these functions
  2. try the generated function structure in an online compiler or the actual robot
  3. See error

Expected behavior

  • the automaticcaly generated function names should either be called _run and _main
  • or functions should not be able to be named main or run

Additional context

  • in java programs the name main is fine due to overloading and it beeing impossible for a user to create a method void main (String[] args) however run() beeing used twice would not compile
  • this does not happen for calliope functions will automatically be named main2

heini208 avatar Jan 07 '22 13:01 heini208

It is recommended to fix this first in blockly. There we have for each programming language a list of illegal names.

bjost2s avatar Aug 25 '22 13:08 bjost2s

solved

rbudde avatar Sep 21 '22 11:09 rbudde