Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include return param names in modified namespaced compilation #1050

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading