misti
misti copied to clipboard
ReadOnlyVariables: Don't suggest creating a constant from a dynamic rhs
Current behavior
fun test(): Int {
let a: Int = random(1, 2);
if (a < 50) { return 1; } else { return 2; }
}
Reported:
../TON-Projects/tact-template/sources/contract.tact:2:7:
1 | fun test(): Int {
> 2 | let a: Int = random(1, 2);
^
3 | if (a < 50) { return 1; } else { return 2; }
Read-only variable
Help: Consider creating a constant instead
Expected behavior No report, since rhs of the variable definition contains function call. Therefore, we cannot create a constant from it.
This should be fixed when https://github.com/nowarp/misti/issues/69 is finised.
If it's a pure function being called then we can keep the current behavior. We need to add purity checker in the Tact typechecker, though: https://github.com/tact-lang/tact/issues/677
One more example of this issue which might be useful for tests when this is resolved:
fun loadFwdPayloadContent(slice: Slice): Slice {
let isRef = slice.loadBool();
if (isRef) { return slice.loadRef().beginParse() }
return slice;
}