From ad1d19f3d89a0609a7cd8d2250730800f2ddefac Mon Sep 17 00:00:00 2001 From: "Congcong Cai (ext.)" Date: Fri, 22 Oct 2021 19:41:42 +0800 Subject: [PATCH 1/3] fix: compileSwitchStatement will hide inner conditional flags --- src/compiler.ts | 3 ++- src/flow.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 9ad5925ab3..301c5ca506 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2969,7 +2969,8 @@ export class Compiler extends DiagnosticEmitter { if (terminates || isLast || innerFlow.isAny(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) { commonCategorical &= innerFlow.flags; } - commonConditional |= innerFlow.flags & FlowFlags.ANY_CONDITIONAL; + + commonConditional |= innerFlow.getConditionFlags(); // Switch back to the parent flow innerFlow.unset( diff --git a/src/flow.ts b/src/flow.ts index d685df7409..98efa5ba09 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -266,6 +266,26 @@ export class Flow { /** Unsets the specified flag or flags. */ unset(flag: FlowFlags): void { this.flags &= ~flag; } + getConditionFlags(): FlowFlags { + let condiFlags = this.flags & FlowFlags.ANY_CONDITIONAL; + if (this.is(FlowFlags.RETURNS)) { + condiFlags |= FlowFlags.CONDITIONALLY_RETURNS; + } + if (this.is(FlowFlags.THROWS)) { + condiFlags |= FlowFlags.CONDITIONALLY_THROWS; + } + if (this.is(FlowFlags.BREAKS)) { + condiFlags |= FlowFlags.CONDITIONALLY_BREAKS; + } + if (this.is(FlowFlags.CONTINUES)) { + condiFlags |= FlowFlags.CONDITIONALLY_CONTINUES; + } + if (this.is(FlowFlags.ACCESSES_THIS)) { + condiFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS; + } + return condiFlags; + } + /** Forks this flow to a child flow. */ fork(resetBreakContext: bool = false): Flow { var branch = new Flow(this.parentFunction); From 689fa74ec534327afa71c532a18d337cd8aa06ae Mon Sep 17 00:00:00 2001 From: dcode Date: Wed, 10 Nov 2021 23:58:29 +0100 Subject: [PATCH 2/3] Update src/flow.ts --- src/flow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flow.ts b/src/flow.ts index 98efa5ba09..c8923f3b11 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -266,7 +266,7 @@ export class Flow { /** Unsets the specified flag or flags. */ unset(flag: FlowFlags): void { this.flags &= ~flag; } - getConditionFlags(): FlowFlags { + deriveConditionalFlags(): FlowFlags { let condiFlags = this.flags & FlowFlags.ANY_CONDITIONAL; if (this.is(FlowFlags.RETURNS)) { condiFlags |= FlowFlags.CONDITIONALLY_RETURNS; From 60a51c786804f0f1edb6b4023f568e9ff8dc370e Mon Sep 17 00:00:00 2001 From: dcode Date: Wed, 10 Nov 2021 23:58:33 +0100 Subject: [PATCH 3/3] Update src/compiler.ts --- src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 301c5ca506..cb939cfd86 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2970,7 +2970,7 @@ export class Compiler extends DiagnosticEmitter { commonCategorical &= innerFlow.flags; } - commonConditional |= innerFlow.getConditionFlags(); + commonConditional |= innerFlow.deriveConditionalFlags(); // Switch back to the parent flow innerFlow.unset(