tomitrescak / clara-support

0 stars 0 forks source link

Compiler bug #107

Closed antonwsu closed 2 years ago

antonwsu commented 3 years ago

Inserting the method below anywhere in your code would disable the "run" button and no error will be reported. This is due to missing "int" in the for-loop and the lack of curly brackets. Having no curly brackets should be allowed.

void initWorld()
{
    for (x = 0; x < WORLD_WIDTH; x++)
        for (y = 0; y < WORLD_WIDTH; y++)
            if (Clara.getRandomNumber(2) == 1)
                putLeaf(x, y);
}
tomitrescak commented 2 years ago

I cannot reproduce this.

  1. If x is not defined I get the correct message:

image

  1. If x is defined globally, the button is enabled:

image

But there IS a bug when there is no int as the generated code is incorrect

tomitrescak commented 2 years ago

Fixed, covered with the following test case:

it('variable can be introduced globally', () => {
  expect(`
    int i;
    void run()
    {        
        int length = 10;
        for (i = 0; i < length; i++ ) 
          i++;
    };

  `).toCompileMethodsTo(`
    constructor() {
      this.i = 0;
    }
    run() {
      let length = 10;
      for (this.i = 0; this.i < length; this.i++) {
        this.i++;
      }
    }
  `);
});