Skip to content

Commit

Permalink
Include return param names in modified namespaced compilation (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau authored Jul 22, 2024
1 parent 6a9aef6 commit 742415c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.34.4 (2024-07-22)

- Fix Hardhat compile error when return parameter names are documented as param. ([#1050](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1050))

## 1.34.3 (2024-07-19)

- Fix Hardhat compile error when multiple return parameters are documented. ([#1048](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1048))
Expand Down
14 changes: 14 additions & 0 deletions packages/core/contracts/test/NamespacedToModify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ function hasMultipleReturns() pure returns (uint, uint) {
function hasMultipleNamedReturns() pure returns (uint a, uint b) {
}

/**
* @param a first
* @param b second
*/
function hasReturnsDocumentedAsParams() pure returns (uint a, uint b) {
}

contract HasNatSpecWithMultipleReturns {
/**
* @return uint 1
Expand All @@ -245,4 +252,11 @@ contract HasNatSpecWithMultipleReturns {
*/
function hasMultipleNamedReturnsInContract() public pure returns (uint a, uint b) {
}

/**
* @param a first
* @param b second
*/
function hasReturnsDocumentedAsParamsInContract() public pure returns (uint a, uint b) {
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openzeppelin/upgrades-core",
"version": "1.34.3",
"version": "1.34.4",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
"license": "MIT",
Expand Down
22 changes: 17 additions & 5 deletions packages/core/src/utils/make-namespaced.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Generated by [AVA](https://avajs.dev).
bytes32 private constant MAIN_STORAGE_LOCATION =␊
0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500;␊
function _getMainStorage() private pure returns (bool) {}␊
function _getMainStorage() private pure returns (bool $) {}␊
function _getXTimesY() internal view returns (bool) {}␊
Expand Down Expand Up @@ -221,26 +221,38 @@ Generated by [AVA](https://avajs.dev).
* @return uint 1␊
* @return uint 2␊
*/␊
function hasMultipleReturns() pure returns (bool,bool) {}␊
function hasMultipleReturns() pure returns (bool, bool) {}␊
/**␊
* @return a first␊
* @return b second␊
*/␊
function hasMultipleNamedReturns() pure returns (bool,bool) {}␊
function hasMultipleNamedReturns() pure returns (bool a, bool b) {}␊
/**␊
* @param a first␊
* @param b second␊
*/␊
function hasReturnsDocumentedAsParams() pure returns (bool a, bool b) {}␊
contract HasNatSpecWithMultipleReturns {␊
/**␊
* @return uint 1␊
* @return uint 2␊
*/␊
function hasMultipleReturnsInContract() public pure returns (bool,bool) {}␊
function hasMultipleReturnsInContract() public pure returns (bool, bool) {}␊
/**␊
* @return a first␊
* @return b second␊
*/␊
function hasMultipleNamedReturnsInContract() public pure returns (bool,bool) {}␊
function hasMultipleNamedReturnsInContract() public pure returns (bool a, bool b) {}␊
/**␊
* @param a first␊
* @param b second␊
*/␊
function hasReturnsDocumentedAsParamsInContract() public pure returns (bool a, bool b) {}␊
}␊
`,
},
Expand Down
Binary file modified packages/core/src/utils/make-namespaced.test.ts.snap
Binary file not shown.
16 changes: 14 additions & 2 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Node } from 'solidity-ast/node';
import { SolcInput, SolcOutput } from '../solc-api';
import { getStorageLocationAnnotation } from '../storage/namespace';
import { assert } from './assert';
import { FunctionDefinition } from 'solidity-ast';
import { FunctionDefinition, VariableDeclaration } from 'solidity-ast';

const OUTPUT_SELECTION = {
'*': {
Expand Down Expand Up @@ -176,7 +176,11 @@ function replaceFunction(node: FunctionDefinition, orig: Buffer, modifications:

if (node.returnParameters.parameters.length > 0) {
modifications.push(
makeReplace(node.returnParameters, orig, `(${node.returnParameters.parameters.map(() => 'bool').join(',')})`),
makeReplace(
node.returnParameters,
orig,
`(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`,
),
);
}

Expand All @@ -186,6 +190,14 @@ function replaceFunction(node: FunctionDefinition, orig: Buffer, modifications:
}
}

function toReturnParameterReplacement(param: VariableDeclaration) {
if (param.name.length > 0) {
return `bool ${param.name}`;
} else {
return 'bool';
}
}

function getPositions(node: Node) {
const [start, length] = node.src.split(':').map(Number);
const end = start + length;
Expand Down

0 comments on commit 742415c

Please sign in to comment.