Skip to content

Commit 70013e9

Browse files
author
Congcong Cai
authored
fix: Propagate inner conditional flags in switch statements (AssemblyScript#2102)
1 parent 02a3e75 commit 70013e9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/compiler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,8 @@ export class Compiler extends DiagnosticEmitter {
29722972
if (terminates || isLast || innerFlow.isAny(FlowFlags.BREAKS | FlowFlags.CONDITIONALLY_BREAKS)) {
29732973
commonCategorical &= innerFlow.flags;
29742974
}
2975-
commonConditional |= innerFlow.flags & FlowFlags.ANY_CONDITIONAL;
2975+
2976+
commonConditional |= innerFlow.deriveConditionalFlags();
29762977

29772978
// Switch back to the parent flow
29782979
innerFlow.unset(

src/flow.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,26 @@ export class Flow {
266266
/** Unsets the specified flag or flags. */
267267
unset(flag: FlowFlags): void { this.flags &= ~flag; }
268268

269+
deriveConditionalFlags(): FlowFlags {
270+
let condiFlags = this.flags & FlowFlags.ANY_CONDITIONAL;
271+
if (this.is(FlowFlags.RETURNS)) {
272+
condiFlags |= FlowFlags.CONDITIONALLY_RETURNS;
273+
}
274+
if (this.is(FlowFlags.THROWS)) {
275+
condiFlags |= FlowFlags.CONDITIONALLY_THROWS;
276+
}
277+
if (this.is(FlowFlags.BREAKS)) {
278+
condiFlags |= FlowFlags.CONDITIONALLY_BREAKS;
279+
}
280+
if (this.is(FlowFlags.CONTINUES)) {
281+
condiFlags |= FlowFlags.CONDITIONALLY_CONTINUES;
282+
}
283+
if (this.is(FlowFlags.ACCESSES_THIS)) {
284+
condiFlags |= FlowFlags.CONDITIONALLY_ACCESSES_THIS;
285+
}
286+
return condiFlags;
287+
}
288+
269289
/** Forks this flow to a child flow. */
270290
fork(resetBreakContext: bool = false): Flow {
271291
var branch = new Flow(this.parentFunction);

0 commit comments

Comments
 (0)