Skip to content

Commit

Permalink
Fix handling of array slices without start and/or end (#473)
Browse files Browse the repository at this point in the history
* Upgrade solidity parser

* Handle array slices without start and/or end
  • Loading branch information
fvictorio authored Apr 15, 2021
1 parent d667e31 commit 3cf089b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"outdent": "^0.8.0"
},
"dependencies": {
"@solidity-parser/parser": "^0.12.0",
"@solidity-parser/parser": "^0.12.1",
"dir-to-object": "^2.0.0",
"emoji-regex": "^9.2.1",
"escape-string-regexp": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/IndexRangeAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const {
} = require('prettier/standalone');

const IndexRangeAccess = {
print: ({ path, print }) =>
print: ({ node, path, print }) =>
concat([
path.call(print, 'base'),
'[',
path.call(print, 'indexStart'),
node.indexStart ? path.call(print, 'indexStart') : '',
':',
path.call(print, 'indexEnd'),
node.indexEnd ? path.call(print, 'indexEnd') : '',
']'
])
};
Expand Down
8 changes: 8 additions & 0 deletions tests/Arrays/Arrays.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ contract Arrays {
Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome, (Outcome.OutcomeItem[]));
}
}

contract ArraySlices {
function f(bytes calldata x) public {
bytes memory a1 = abi.decode(x[:], (bytes));
bytes4 a2 = abi.decode(x[:4], (bytes4));
address a3 = abi.decode(x[4:], (address));
}
}
16 changes: 16 additions & 0 deletions tests/Arrays/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ contract Arrays {
}
}
contract ArraySlices {
function f(bytes calldata x) public {
bytes memory a1 = abi.decode(x[:], (bytes));
bytes4 a2 = abi.decode(x[:4], (bytes4));
address a3 = abi.decode(x[4:], (address));
}
}
=====================================output=====================================
pragma solidity ^0.5.2;
Expand All @@ -41,5 +49,13 @@ contract Arrays {
}
}
contract ArraySlices {
function f(bytes calldata x) public {
bytes memory a1 = abi.decode(x[:], (bytes));
bytes4 a2 = abi.decode(x[:4], (bytes4));
address a3 = abi.decode(x[4:], (address));
}
}
================================================================================
`;

0 comments on commit 3cf089b

Please sign in to comment.