Skip to content

Commit 8c64418

Browse files
authored
Print returns in function types at the end (#333)
1 parent de4ff5e commit 8c64418

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

Foo.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract FunctionTypes {
2+
struct Something {
3+
function (address) external view returns (uint256) getSomething;
4+
}
5+
6+
function reduce(
7+
uint256[] memory self,
8+
function (uint256, uint256) pure returns (uint256) f
9+
) internal pure returns (uint256 r) {
10+
r = self[0];
11+
for (uint256 i = 1; i < self.length; i++) {
12+
r = f(r, self[i]);
13+
}
14+
}
15+
}

src/nodes/FunctionTypeName.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ const FunctionTypeName = {
3535
indent(
3636
group(
3737
concat([
38-
returnTypes(node, path, print),
3938
visibility(node),
40-
stateMutability(node)
39+
stateMutability(node),
40+
returnTypes(node, path, print)
4141
])
4242
)
4343
)

tests/AllSolidityFeatures/AllSolidityFeatures.sol

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,19 @@ contract ConstructorWithoutVisibility {
486486
x = _x;
487487
}
488488
}
489+
490+
contract FunctionTypes {
491+
struct Something {
492+
function (address) external view returns (uint256) getSomething;
493+
}
494+
495+
function reduce(
496+
uint256[] memory self,
497+
function (uint256, uint256) pure returns (uint256) f
498+
) internal pure returns (uint256 r) {
499+
r = self[0];
500+
for (uint256 i = 1; i < self.length; i++) {
501+
r = f(r, self[i]);
502+
}
503+
}
504+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,22 @@ contract ConstructorWithoutVisibility {
489489
x = _x;
490490
}
491491
}
492+
493+
contract FunctionTypes {
494+
struct Something {
495+
function (address) external view returns (uint256) getSomething;
496+
}
497+
498+
function reduce(
499+
uint256[] memory self,
500+
function (uint256, uint256) pure returns (uint256) f
501+
) internal pure returns (uint256 r) {
502+
r = self[0];
503+
for (uint256 i = 1; i < self.length; i++) {
504+
r = f(r, self[i]);
505+
}
506+
}
507+
}
492508
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
493509
// Examples taken from the Solidity documentation online.
494510
@@ -1028,4 +1044,20 @@ contract ConstructorWithoutVisibility {
10281044
}
10291045
}
10301046
1047+
contract FunctionTypes {
1048+
struct Something {
1049+
function(address) external view returns (uint256) getSomething;
1050+
}
1051+
1052+
function reduce(
1053+
uint256[] memory self,
1054+
function(uint256, uint256) pure returns (uint256) f
1055+
) internal pure returns (uint256 r) {
1056+
r = self[0];
1057+
for (uint256 i = 1; i < self.length; i++) {
1058+
r = f(r, self[i]);
1059+
}
1060+
}
1061+
}
1062+
10311063
`;

0 commit comments

Comments
 (0)