tact
tact copied to clipboard
Compilation errors when enabling `debug` in `WriterContext.extract`
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
- Enforce debug-mode here: https://github.com/tact-lang/tact/blob/12def54b4b17417dda06cbf0e7e411f003504f8a/src/generator/Writer.ts#L70
- 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;
}
- 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.