PS: Fix missing variables #292
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR: This PR fixes a bug related to local variable resolution.
Slightly longer:
One of the very earliest things that happen in QL for most languages is local variable resolution. That is, resolving which variable a read or write affects. This is pretty straightforward, but care must be taken to limit the scope of variable as much as possible for performance reasons.
Compiled languages often have the luxury of a variable declaration which clearly defines where a variable is introduced. However, that's not the case for mots dynamic languages (such as PowerShell). Instead, the scope of a variable is identified by finding the scope in which the variable is written to, and any nested scope is then a scope in which the variable is available. So when we see something like:
we know that
$xis in scope in the outer scope (which assigns$x) and the inner scopes (i.e., the branches of theif).Thus, it's clear that we need to identify which variable occurs on the left-hand side of an assignment. However, it turned out that we had forgotten that the left-hand side could be a conversion such as:
and in that case we failed to deduce the assignment to
$x, and thus the scope of$x, and thus any flow involving$xwas totally lost.Commit-by-commit review recommended: