External Issue: Odd bug with 'ref' parameter

16935, “npadmana”, “Odd bug with ‘ref’ parameter”, “2021-01-13T00:46:53Z”

Summary of Problem

Getting different behavior depending on whether a call is inside a block or not.

Steps to Reproduce

Source Code:

class Base {
  proc ff(ref ipos : int) {};
}

class A : Base {
  override proc ff(ref ipos : int) {
    ipos += 1;
  }
}

var x : owned Base? = new owned A();

var ipos1 = 0;
x!.ff(ipos1);
writeln(ipos1);

// Why do I get a different answer here?
{
  var ipos = 0;
  x!.ff(ipos);
  writeln(ipos);
}

Running this, I get

1
0

while I would have expected

1
1

If I change the variable declaration to var x : owned A? = ..., then it works correctly.

@e-kayrakli also pointed out on gitter that

  • compiling with -no-copy-propagation gets the code to work.
  • writing the code as ref iposRef = ipos; and then using iposRef in the call works as well.