Skip to content

&& and || expression will not change the NONNULL flag #2359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HerrCai0907 opened this issue Jul 4, 2022 · 2 comments
Closed

&& and || expression will not change the NONNULL flag #2359

HerrCai0907 opened this issue Jul 4, 2022 · 2 comments
Labels

Comments

@HerrCai0907
Copy link
Member

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 HerrCai0907 added the bug label Jul 4, 2022
HerrCai0907 added a commit to HerrCai0907/assemblyscript that referenced this issue Jul 4, 2022
@dcodeIO
Copy link
Member

dcodeIO commented Jul 4, 2022

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
Copy link
Member

dcodeIO commented Nov 29, 2022

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 dcodeIO closed this as completed Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants