assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

`&&` and `||` expression will not change the `NONNULL` flag

Open HerrCai0907 opened this issue 3 years ago • 1 comments

This code should not pass the compile.

export function _start(): void {
  let value: A | null = new A();
  if (value != null) {
    // value = null;  // cause compile error correctly
    true && (value = null); // compile passed, but value is changed to zero now
    let a1 = value.a1;
  }
}

HerrCai0907 avatar Jul 04 '22 01:07 HerrCai0907

Looking at this briefly, the cause here seems to be in the && respectively || cases in Compiler#compileBinaryExpression, where the state of rightFlow is not inherited by the parent flow, so its mutations are lost.

dcodeIO avatar Jul 04 '22 01:07 dcodeIO

This issue will be addressed as part of #2578 (not yet merged) alongside a broader refactoring of the relevant flow logic solving similar issues in other places.

dcodeIO avatar Nov 29 '22 17:11 dcodeIO