Skip to content

Commit

Permalink
Fixed #219, correcting conditional guard logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 24, 2023
1 parent 45e11ac commit c414ae2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/nodes/Conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,20 @@ export default class Conditional extends Expression {
context
);

// The condition did some guarding if the intersection of the revised and current sets is smaller than the current set
const guarded =
current.intersection(revisedTypes, context).size() < current.size();

// Evaluate the yes branch with the revised types.
if (this.yes instanceof Expression)
this.yes.evaluateTypeSet(bind, original, revisedTypes, context);

// Evaluate the no branch with the complement of the revised types.
// Evaluate the no branch with the complement of the revised types, unless they weren't guarded, in which case we pass through the current types.
if (this.no instanceof Expression) {
this.no.evaluateTypeSet(
bind,
original,
current.difference(revisedTypes, context),
guarded ? current.difference(revisedTypes, context) : current,
context
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default abstract class Expression extends Node {
}

/**
* Used to determine what types are possible for a given after evalutaing this expression/
* Used to determine what types are possible for a given after evaluating this expression, implementing type guards.
* Most expressions do not manipulate possible types at all; primarily is just logical operators and type checks.
* */
abstract evaluateTypeSet(
Expand Down

0 comments on commit c414ae2

Please sign in to comment.