stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

[Bug] Function inliner fails when a variable name is the same as one in the enclosing scope #1229

Closed WardBrian closed 2 years ago

WardBrian commented 2 years ago

MRE:

functions {
  vector foo(vector oR) {
    int ot = num_elements(oR);

    vector[ot] R = oR;

    return (R);
  }
}
data {
  int N;
}
transformed parameters {
  vector[N] R;
  vector[N] out;
  out = foo(R);
}

Renaming R in either the transformed parameters block or in the function resolves the issue. I believe the issue stems from here

Pinging @SteveBronder

Originally posted by @WardBrian in https://github.com/stan-dev/stanc3/issues/1227#issuecomment-1194319053