Skip to content
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

Explicitly handle undefined result from Array.pop() #64

Merged
merged 2 commits into from
Oct 10, 2016

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Oct 10, 2016

This pull request corrects two cases where the result of calling pop() is being treated as T | undefined, by updating the code so the compiler recognizes that the value is actually known to be T.

📝 Strict null checks are currently disabled, but we're working to change that. See #26.

@@ -627,8 +627,11 @@ class ArrayPredictionContext extends PredictionContext {
let otherWorkList: PredictionContext[] = [];
selfWorkList.push(this);
otherWorkList.push(other);
while (selfWorkList.length > 0) {
let operands: PredictionContextCache.IdentityCommutativePredictionContextOperands = new PredictionContextCache.IdentityCommutativePredictionContextOperands(selfWorkList.pop(), otherWorkList.pop());
for (let currentSelf = selfWorkList.pop(), currentOther = otherWorkList.pop();
Copy link
Member Author

Choose a reason for hiding this comment

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

❓ Is the following style easier to read?

while (true) {
  let currentSelf = selfWorkList.pop();
  let currentOther = otherWorkList.pop();
  if (!currentSelf || !currentOther) {
    break;
  }

  let operands...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think the while seems easier to comprehend.

@BurtHarris BurtHarris assigned sharwell and unassigned BurtHarris Oct 10, 2016
@sharwell sharwell assigned BurtHarris and unassigned sharwell Oct 10, 2016
@BurtHarris BurtHarris merged commit 3dc65b5 into master Oct 10, 2016
@sharwell sharwell deleted the pop-undefined branch October 10, 2016 21:30
@BurtHarris BurtHarris removed their assignment Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants