misti icon indicating copy to clipboard operation
misti copied to clipboard

ReadOnlyVariables: Don't suggest creating a constant from a dynamic rhs

Open jubnzv opened this issue 1 year ago • 2 comments

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.

jubnzv avatar Aug 12 '24 10:08 jubnzv

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

anton-trunov avatar Aug 12 '24 10:08 anton-trunov

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;
}

anton-trunov avatar Aug 28 '24 15:08 anton-trunov