Skip to content

Commit

Permalink
Print returns in function types at the end (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio authored Sep 5, 2020
1 parent de4ff5e commit 8c64418
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Foo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contract FunctionTypes {
struct Something {
function (address) external view returns (uint256) getSomething;
}

function reduce(
uint256[] memory self,
function (uint256, uint256) pure returns (uint256) f
) internal pure returns (uint256 r) {
r = self[0];
for (uint256 i = 1; i < self.length; i++) {
r = f(r, self[i]);
}
}
}
4 changes: 2 additions & 2 deletions src/nodes/FunctionTypeName.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const FunctionTypeName = {
indent(
group(
concat([
returnTypes(node, path, print),
visibility(node),
stateMutability(node)
stateMutability(node),
returnTypes(node, path, print)
])
)
)
Expand Down
16 changes: 16 additions & 0 deletions tests/AllSolidityFeatures/AllSolidityFeatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,19 @@ contract ConstructorWithoutVisibility {
x = _x;
}
}

contract FunctionTypes {
struct Something {
function (address) external view returns (uint256) getSomething;
}

function reduce(
uint256[] memory self,
function (uint256, uint256) pure returns (uint256) f
) internal pure returns (uint256 r) {
r = self[0];
for (uint256 i = 1; i < self.length; i++) {
r = f(r, self[i]);
}
}
}
32 changes: 32 additions & 0 deletions tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,22 @@ contract ConstructorWithoutVisibility {
x = _x;
}
}
contract FunctionTypes {
struct Something {
function (address) external view returns (uint256) getSomething;
}
function reduce(
uint256[] memory self,
function (uint256, uint256) pure returns (uint256) f
) internal pure returns (uint256 r) {
r = self[0];
for (uint256 i = 1; i < self.length; i++) {
r = f(r, self[i]);
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Examples taken from the Solidity documentation online.
Expand Down Expand Up @@ -1028,4 +1044,20 @@ contract ConstructorWithoutVisibility {
}
}
contract FunctionTypes {
struct Something {
function(address) external view returns (uint256) getSomething;
}
function reduce(
uint256[] memory self,
function(uint256, uint256) pure returns (uint256) f
) internal pure returns (uint256 r) {
r = self[0];
for (uint256 i = 1; i < self.length; i++) {
r = f(r, self[i]);
}
}
}
`;

0 comments on commit 8c64418

Please sign in to comment.