Skip to content

Commit fe32e08

Browse files
authored
Patch assignment (#1454)
* Edge case for assignments * patch version * fix lint * ignoring comparison with ANTLR
1 parent 0d1c450 commit fe32e08

7 files changed

Lines changed: 71 additions & 3 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "prettier-plugin-solidity",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
55
"type": "module",
66
"main": "./dist/index.js",

src/slang-printers/print-assignment-right-side.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function printAssignmentRightSide(
1212
return printIndentedGroupOrSpacedDocument(
1313
document,
1414
value.kind !== NonterminalKind.ArrayExpression &&
15+
value.kind !== NonterminalKind.TupleExpression &&
1516
!isChainableExpression(value)
1617
);
1718
}

tests/config/run-format-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const antlrMismatchTests = new Map(
8585
// ANTLR doesn't support UntypedTupleMember with a storage location, which
8686
// is valid Slang, but not in Solidity.
8787
"AllSolidityFeaturesV0.4.26/AllSolidityFeatures.sol",
88+
// TODO Review how ANTLR is formatting chained assignments
89+
"Assignments/Assignments.sol",
8890
].map((fixture) => {
8991
const [file, compareBytecode = () => true] = Array.isArray(fixture)
9092
? fixture
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract Assignments {
2+
address payable public inParentheses = (contractPointer.functionCall(data.data1,data.data2,IERC20(data.token).decimals(),currency));
3+
uint[] internal longArray = [item1,item2,item3,item4,item5,item6,item7,item8,item9,itema,itemb,itemc,itemd,iteme];
4+
// TODO research what we want to do with chained assignments
5+
function chainedAssignments() returns (bytes32 variableA, bytes32 variableB) {
6+
variableA = variableB = 0x1234567890abcdef1234567890abcdef ^ 0x1234567890abcdef1234567890abcdef;
7+
}
8+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`Assignments.sol format 1`] = `
4+
====================================options=====================================
5+
parsers: ["slang"]
6+
printWidth: 80
7+
| printWidth
8+
=====================================input======================================
9+
contract Assignments {
10+
address payable public inParentheses = (contractPointer.functionCall(data.data1,data.data2,IERC20(data.token).decimals(),currency));
11+
uint[] internal longArray = [item1,item2,item3,item4,item5,item6,item7,item8,item9,itema,itemb,itemc,itemd,iteme];
12+
// TODO research what we want to do with chained assignments
13+
function chainedAssignments() returns (bytes32 variableA, bytes32 variableB) {
14+
variableA = variableB = 0x1234567890abcdef1234567890abcdef ^ 0x1234567890abcdef1234567890abcdef;
15+
}
16+
}
17+
18+
=====================================output=====================================
19+
contract Assignments {
20+
address payable public inParentheses = (
21+
contractPointer.functionCall(
22+
data.data1,
23+
data.data2,
24+
IERC20(data.token).decimals(),
25+
currency
26+
)
27+
);
28+
uint[] internal longArray = [
29+
item1,
30+
item2,
31+
item3,
32+
item4,
33+
item5,
34+
item6,
35+
item7,
36+
item8,
37+
item9,
38+
itema,
39+
itemb,
40+
itemc,
41+
itemd,
42+
iteme
43+
];
44+
// TODO research what we want to do with chained assignments
45+
function chainedAssignments()
46+
returns (bytes32 variableA, bytes32 variableB)
47+
{
48+
variableA =
49+
variableB =
50+
0x1234567890abcdef1234567890abcdef ^
51+
0x1234567890abcdef1234567890abcdef;
52+
}
53+
}
54+
55+
================================================================================
56+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runFormatTest(import.meta, ['slang']);

0 commit comments

Comments
 (0)