parapluu / encore

The Encore compiler.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiling Forward to Method with Arguments Generates Broken C

supercooldave opened this issue · comments

The following simple example

active class Main
  def main() : unit
    (new Worker()) ! seq(10)
  end
end

active class Worker
  def seq(s : int) : unit
    if s > 0 then
      forward (this!seq(s - 1))  -- FAILS TO COMPILE
      -- this.seq(s - 1)         -- COMPILES
    end
  end
end

results in broken C

BrokenForward_src/Worker.encore.c:185:73: error: use of undeclared identifier
      '_binop_7'; did you mean '_binop_4'?
  ..._this, NULL, _binop_7);
                  ^~~~~~~~
                  _binop_4
BrokenForward_src/Worker.encore.c:177:13: note: '_binop_4' declared here
    int64_t _binop_4 = (({ _enc__arg_s;}) - ({int64_t _literal_3 = 1; _l...
            ^
1 error generated.

Looking at the test directory, it seems that forward is not tested with methods that take arguments.

After doing some tests, it is clear that the bug is due to the expression s - 1 in the call to seq.
If s - 1 is replaced by, for example, s, this compiles.