diff --git a/Foo.sol b/Foo.sol new file mode 100644 index 000000000..d437e77ef --- /dev/null +++ b/Foo.sol @@ -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]); + } + } +} diff --git a/src/nodes/FunctionTypeName.js b/src/nodes/FunctionTypeName.js index 585880481..27f4cc595 100644 --- a/src/nodes/FunctionTypeName.js +++ b/src/nodes/FunctionTypeName.js @@ -35,9 +35,9 @@ const FunctionTypeName = { indent( group( concat([ - returnTypes(node, path, print), visibility(node), - stateMutability(node) + stateMutability(node), + returnTypes(node, path, print) ]) ) ) diff --git a/tests/AllSolidityFeatures/AllSolidityFeatures.sol b/tests/AllSolidityFeatures/AllSolidityFeatures.sol index bd69316e2..e1579af2c 100644 --- a/tests/AllSolidityFeatures/AllSolidityFeatures.sol +++ b/tests/AllSolidityFeatures/AllSolidityFeatures.sol @@ -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]); + } + } +} diff --git a/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap b/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap index 71921ec3c..51e117346 100644 --- a/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap +++ b/tests/AllSolidityFeatures/__snapshots__/jsfmt.spec.js.snap @@ -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. @@ -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]); + } + } +} + `;