Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local variables through let expressions are broken #6

Closed
TobiasWrigstad opened this issue Jul 18, 2014 · 8 comments
Closed

Local variables through let expressions are broken #6

TobiasWrigstad opened this issue Jul 18, 2014 · 8 comments
Assignees

Comments

@TobiasWrigstad
Copy link
Contributor

I am compiling this code:

let i = this.start in 
  while i < this.stop 
    {
      if this.prime_array.is_not_flagged(i) then this.pass_on(i) else ();
      i = i + 1
    };

in which I expect that i is a local variable, whose initial value is that of this.start, and for each turn in the loop, i is incremented by 1.

However, the code that I see generated is the following:

void* _tmp9;
while (({;
         ;
         int _tmp3 = ((*this).start < (*this).stop);;; _tmp3;}))
{
  void* _tmp4_ite;
  if (({int _tmp6 = PrimeArray_is_not_flagged((*this).prime_array, ({ (*this).start;})); _tmp6;}))
  {
    Filter_pass_on(this, ({ (*this).start;}));;
    _tmp4_ite = UNIT;;;
  }
  else
  {
    UNIT;;
    _tmp4_ite = UNIT;;;
  };;
  ;
  int64_t _tmp7 = 1;;
  int64_t _tmp8 = ((*this).start + _tmp7);;;;
  ;
  (*this).start = _tmp8;;;;;
  _tmp9 = UNIT;;;
};;;

which replaces i with this.start and modifies this.start in each increment! This clearly cannot be right, right?

@kaeluka kaeluka self-assigned this Jul 18, 2014
@supercooldave
Copy link

This is not right.

Sent from my iPhone

@TobiasWrigstad
Copy link
Contributor Author

Here is a test that reproduces the bug (I will commit it to the repo)

class Main
  value : int
  def main() : void {
    this.value = 1024;
    let x = this.value in {
      x = x + 1;
      if x == 1024 then
        print "Failue when reading x -- expected 1024, got something else"
      else
        print "Test 1 OK";
      if x == this.value then
        print "Failue when comparing x and this.value -- they are the same but should not be"
      else
        print "Test 2 OK";
    }
  }

When run, this prints out

Test 1 OK
Failue when comparing x and this.value -- they are the same but should not be

@supercooldave
Copy link

Shouldn't it read "expected 1025"?

@kaeluka
Copy link
Contributor

kaeluka commented Jul 18, 2014

Found the bug, fix should be easy.

@TobiasWrigstad
Copy link
Contributor Author

@supercooldave The key thing is not the value, but that the value of the field and variable are different. If they are both at 1025, bug still persists.

@supercooldave
Copy link

My comment was on the text of the test case.

@TobiasWrigstad
Copy link
Contributor Author

@supercooldave Right! My bad. I'll fix.

EDIT Fixed. It now reads "Got 1024, expected something else" :)

kaeluka pushed a commit that referenced this issue Jul 18, 2014
#6

Field accesses were translated without a `_tmpN` variable.
@kaeluka
Copy link
Contributor

kaeluka commented Jul 18, 2014

0e31620 The test passes now.

@kaeluka kaeluka closed this as completed Jul 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants