This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
Fix modifier argument detection by factoring out no-op handling #6168
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.
PR description
This PR fixes an old bug regarding detection of arguments to modifiers, and factors some code in the process.
Both mapping key handling and modifier argument detection can require looking inside nodes that aren't sourcemapped because they're no-ops on the EVM level and so don't correspond to any instruction. (Certain type conversions; unary plus in Solidity prior to 0.5.0; and
wrap
/unwrap
for UDVTs.) When dealing with these, we often need to peel away the node representing the no-op, to find the node inside representing an actual operation.For mapping-key handling, this code has been kept up to date. But for modifier argument detection, which had the logic separate, it was not. I didn't notice this until going over the code with @cds-amal this past Friday.
This PR factors out the logic into a function in
helpers
, unifying the two places it's used. So now the up-to-date logic from mapping key handling is applied to modifier argument detection as well. And if there's ever any further need to update this, now the code will all be in one place so it won't desync like that again!I used some fairly C-style loops in this one, hope you don't mind, it seemed the easiest way. :P
Testing instructions
I didn't bother adding any tests for this one, I just did some brief manual testing. I tested using the
modifier-test-8
project in thesolidity-test-cases
repo.