Fix incorrect block scoping rules for legacy code #165
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.
The scoping rules in ast/definitions.ts incorrectly handle pre-0.5 blocks. Looking up a variable in a block should resolve to any VariableDeclaration anywhere in the block.
In the code below,
y
is equal to16
because the scope is shared throughout the entire block, butresolveAny
will resolve everyxn
to the contract's storage values.Scenario
Expected behavior
x1,x2,x3,x4 resolve to declarations within function
f
with IDs 13, 20, 26, 32.Current behavior
x1,x2,x3,x4 resolve to declarations within contract with IDs 3,5,7,9
Solution
The fix is to search for all
VariableDeclaration
nodes when performing a lookup in the scope of a block when the version is <0.5. I modifiedlookupInBlock
to perform this check and had to changelookupInScope
andresolveAny
to pass along the version. I also updated theblock_04
andblock_05
tests intest/samples/solidity/resolving
to test this behavior.