Current develop breaks old code?


I have these two functions in Stan:

  matrix slice_m(matrix data, int[] S, int s) {
     int l = sum(S[1:(s-1)]);
     int u = l + S[s];

  // given as input a 2D matrix of size NxM and a slicing vector S, the
  // output is a 1D array with each slice flattened to a 1D column major
  // ordering.
  real[] to_array_1d_sliced(matrix data, int[] S) {
    int N = dims(data)[1];
    int M = dims(data)[2];
    real res[N*M];
    int rs = 1;

    for(s in 1:size(S)) {
      res[rs : (rs + M*S[s] - 1)] = to_array_1d(slice_m(data, S, s));
      rs = rs + M*S[s];


In the released 2.14.0 this works just fine. In the current develop of cmdstan I get this complaint:

Illegal statement beginning with non-void expression parsed as
res[rs:((rs + (M * S[s])) - 1)]
Not a legal assignment, sampling, or function statement. Note that

  • Assignment statements only allow variables (with optional indexes) on the left;
    if you see an outer function logical_lt (<) with negated (-) second argument,
    it indicates an assignment statement A <- B with illegal left
    side A parsed as expression (A < (-B)).
  • Sampling statements allow arbitrary value-denoting expressions on the left.
  • Functions used as statements must be declared to have void returns

ERROR at line 819

818: for(s in 1:size(S)) {
819: res[rs : (rs + MS[s] - 1)] = to_array_1d(slice_m(data, S, s));
820: rs = rs + M


Is this a new bug and I should file an issue?

Or asked differently: Were there changes to the parser recently?


I hope I am managing these git modules right, but if yes, then this is a bug either with my code which was never valid or this is truly a new bug. I am filing a new stan issue for this to resolve this.

yes there were changes to the parser which caused this problem. it’s been fixed and changes have been merged into develop. details here: