Skip to content

fix: Fix || and && will not inherit branch status #2360

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

Conversation

HerrCai0907
Copy link
Member

Fix #2359

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@HerrCai0907 HerrCai0907 added the bug label Jul 4, 2022
src/compiler.ts Outdated
@@ -4597,6 +4597,7 @@ export class Compiler extends DiagnosticEmitter {
}
this.currentType = leftType;
}
this.currentFlow.inheritBranch(rightFlow);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little more complex than this I guess. For instance, if the LHS is always true, the parent flow would inherit the right flow unconditionally (not a branch), while if it is always false, the parent flow would not inherit the right flow since it doesn't execute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, inheritBranch is a little conservative. It can spilt with difference LHS/RHS ConditionKind

@HerrCai0907
Copy link
Member Author

@dcodeIO It seems like a little bit complex. After this fix, It still have problem.

export function _start(): void {
  let a: string| null = "hhh"
  if (a && !(a = null)) {
    trace(a.length.toString())
  }
}

wasm://wasm/a4e78d1a:1

RuntimeError: memory access out of bounds
at wasm://wasm/a4e78d1a:wasm-function[2]:0x18c
at wasm://wasm/a4e78d1a:wasm-function[58]:0x14df
at file:///home/ccc/Desktop/demo/as/tests/index.js:3:1

@HerrCai0907 HerrCai0907 marked this pull request as draft July 7, 2022 14:24
@HerrCai0907 HerrCai0907 closed this Aug 9, 2022
@HerrCai0907 HerrCai0907 deleted the fix/nullable-flag-not-set-after-bool-operator branch March 2, 2023 13:28
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 this pull request may close these issues.

&& and || expression will not change the NONNULL flag
2 participants