diff --git a/src/compiler.ts b/src/compiler.ts index 9ad5925ab3..cb939cfd86 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.deriveConditionalFlags(); // Switch back to the parent flow innerFlow.unset( diff --git a/src/flow.ts b/src/flow.ts index d685df7409..c8923f3b11 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; } + deriveConditionalFlags(): 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);