tact icon indicating copy to clipboard operation
tact copied to clipboard

Compilation errors when enabling `debug` in `WriterContext.extract`

Open jubnzv opened this issue 5 months ago • 0 comments

If we turn on debug mode in the WriterContext.extract function, incorrect FunC code will be generated. That feature might be quite useful for the compiler development, in particular for differential testing between backends (#559).

Steps to reproduce

  1. Enforce debug-mode here: https://github.com/tact-lang/tact/blob/12def54b4b17417dda06cbf0e7e411f003504f8a/src/generator/Writer.ts#L70
  2. Compile a simple Tact contract, e.g.:
trait T {
    a: Int = 42;
    get fun getA(): Int {
        return self.a;
    }
}
contract Test with T {
    a: Int = 19;
}
  1. See the error output:
💼 Compiling project sample ...
   > Test: tact compiler
   > Test: func compiler
Func compilation error ./sources/output/sample_Test.stdlib.fc:1238:36: error: cannot apply function $Test$_fun_reply : (int, cell) -> (int, ()) to arguments of type int: cannot unify type int with (int, cell)
      return $self~$Test$_fun_reply();

Problem description

The issue appears because of return types mismatch between these functions: $Test$_fun_reply and $Test$_fun_reply$not_mut.

Generated code:

((int), ()) $Test$_fun_reply((int) $self, cell $body) impure inline {
    var (($self'a)) = $self;
    ($self'a)~$Test$_fun_forward(__tact_context_get_sender(), $body, true, null());
    return (($self'a), ());
}

() $Test$_fun_reply$not_mut((int) $self, cell $body) impure inline {
    return $self~$Test$_fun_reply();
}

The relevant code in backend: https://github.com/tact-lang/tact/blob/12def54b4b17417dda06cbf0e7e411f003504f8a/src/generator/writers/writeFunction.ts#L606.

jubnzv avatar Sep 10 '24 03:09 jubnzv