hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.46k stars 238 forks source link

[BUG] error: a 'forward' return type cannot return a local variable #964

Open wolfseifert opened 8 months ago

wolfseifert commented 8 months ago

Transpiling

Size: type == size_t;
Real: type == double;
Mat: type = {
  Elem: @struct type = {
    entry: Real;
    colind: Size;
  }
  data: ::std::valarray<::std::valarray<Elem>>;
  operator[]: (inout this, row: Size, col: Size) -> forward Real = {
    (inout datarow := data[row]) {
      for datarow do(inout d)
16:     if (d.colind == col) { return d.entry; }
      s := datarow.size();
      ndatarow := ::std::valarray<Elem>(s + 1);
      i: Size = 0;
      while i < s next i++ {
        ndatarow[i] = datarow[i];
      }
      ndatarow[s] = Elem(0.0, col);
      datarow = ndatarow;
25:   return datarow[s].entry;
    }
  }
}

results in two errors:

poisson.cpp2(16,32): error: a 'forward' return type cannot return a local variable
poisson.cpp2(25,7): error: a 'forward' return type cannot return a local variable

This code transpiled without problems with earlier cpp2 versions (some weeks ago).