Skip to content

Commit 3cf089b

Browse files
authored
Fix handling of array slices without start and/or end (#473)
* Upgrade solidity parser * Handle array slices without start and/or end
1 parent d667e31 commit 3cf089b

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"outdent": "^0.8.0"
7575
},
7676
"dependencies": {
77-
"@solidity-parser/parser": "^0.12.0",
77+
"@solidity-parser/parser": "^0.12.1",
7878
"dir-to-object": "^2.0.0",
7979
"emoji-regex": "^9.2.1",
8080
"escape-string-regexp": "^4.0.0",

src/nodes/IndexRangeAccess.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const {
55
} = require('prettier/standalone');
66

77
const IndexRangeAccess = {
8-
print: ({ path, print }) =>
8+
print: ({ node, path, print }) =>
99
concat([
1010
path.call(print, 'base'),
1111
'[',
12-
path.call(print, 'indexStart'),
12+
node.indexStart ? path.call(print, 'indexStart') : '',
1313
':',
14-
path.call(print, 'indexEnd'),
14+
node.indexEnd ? path.call(print, 'indexEnd') : '',
1515
']'
1616
])
1717
};

tests/Arrays/Arrays.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ contract Arrays {
77
Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(fromPart.outcome, (Outcome.OutcomeItem[]));
88
}
99
}
10+
11+
contract ArraySlices {
12+
function f(bytes calldata x) public {
13+
bytes memory a1 = abi.decode(x[:], (bytes));
14+
bytes4 a2 = abi.decode(x[:4], (bytes4));
15+
address a3 = abi.decode(x[4:], (address));
16+
}
17+
}

tests/Arrays/__snapshots__/jsfmt.spec.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ contract Arrays {
1616
}
1717
}
1818
19+
contract ArraySlices {
20+
function f(bytes calldata x) public {
21+
bytes memory a1 = abi.decode(x[:], (bytes));
22+
bytes4 a2 = abi.decode(x[:4], (bytes4));
23+
address a3 = abi.decode(x[4:], (address));
24+
}
25+
}
26+
1927
=====================================output=====================================
2028
pragma solidity ^0.5.2;
2129
@@ -41,5 +49,13 @@ contract Arrays {
4149
}
4250
}
4351
52+
contract ArraySlices {
53+
function f(bytes calldata x) public {
54+
bytes memory a1 = abi.decode(x[:], (bytes));
55+
bytes4 a2 = abi.decode(x[:4], (bytes4));
56+
address a3 = abi.decode(x[4:], (address));
57+
}
58+
}
59+
4460
================================================================================
4561
`;

0 commit comments

Comments
 (0)