From f6d1e358a170103c4d9a96999786b3ebbe97456a Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 22 Jul 2024 13:19:03 -0400 Subject: [PATCH 1/4] Include return param names in modified namespaced compilation --- .../contracts/test/NamespacedToModify.sol | 14 +++++++++++ .../core/src/utils/make-namespaced.test.ts.md | 22 ++++++++++++++---- .../src/utils/make-namespaced.test.ts.snap | Bin 2083 -> 2132 bytes packages/core/src/utils/make-namespaced.ts | 12 ++++++++-- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/packages/core/contracts/test/NamespacedToModify.sol b/packages/core/contracts/test/NamespacedToModify.sol index 52f30a688..5b88b3c76 100644 --- a/packages/core/contracts/test/NamespacedToModify.sol +++ b/packages/core/contracts/test/NamespacedToModify.sol @@ -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 @@ -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) { + } } diff --git a/packages/core/src/utils/make-namespaced.test.ts.md b/packages/core/src/utils/make-namespaced.test.ts.md index 7f573187f..e3ad236ea 100644 --- a/packages/core/src/utils/make-namespaced.test.ts.md +++ b/packages/core/src/utils/make-namespaced.test.ts.md @@ -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) {}␊ ␊ @@ -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) {}␊ }␊ `, }, diff --git a/packages/core/src/utils/make-namespaced.test.ts.snap b/packages/core/src/utils/make-namespaced.test.ts.snap index f7bc81a884c9e3ae76e8d6e6c61e76fe1d06dfb8..b788812eb05fea6a96612bac91868d6171baea3a 100644 GIT binary patch literal 2132 zcmV-a2&?x&RzVvM;Z3oxn62$bEWOw>*#a`PDq@!lQ_{GMYSBa7$wdT z`^p_qtl8ahGL60K&g|xFq7=as67L8kUdk&kyz+oh)rS_|S_xDM9(k&SKuAb^?7y?K z>)Bm9cA{3gNE7eQ{Qp1Se*err|NQTEjhjA0XB(+s6Fsp z%56O0$BxT?_O4}N7eBuBi(KY<#{bh6wS@}&ehV6b_ETstYR|l&J#%2ZMNC)IqQ@II zZe+CQGFmR9ErCq-CI9K#3)*52+eaQgB2h=n=~0Wiqm1^vru`Z$MkAcKF13%i82LaM zxy~JrnS={K|AT?gpdl@jxvwPvW#fPrwcL+D#DMmj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U`|*y}AXha}4}G+^`$djtW!+`|CjV7J-o zwmXMMyKgqS`-k=2PV=yZUW=Wj4=XzxxK^odnHxJhoBC#T)7->6TRmK<8rY~}qo&u) zO`~S%WZN{iH%#5sYX;uh&~<{1EnSyRi;3zU6Hi%-fsZ7pfzJqH#PgZMQOR&!dpTx5 zq5h~tA-+8>DMX)9@?@HBV!gmuTejSti6UXnPdzgDot4l4p9Kns2 z-|vqUCkpde*oP$|yH{31I#-n0VHAmTSq`mdWMc{RgnB1%d?c26ppjmG8xz+1GLtH_xsmRLknQ(@L#vwA;)L;L zooIL!O6%|`exI}t5JaLl_n((0_mW)G^%jhwMP;Zamad3hixVpp#{?dIE!ZXNbzRlS*nDd;X^c=V8yc>fE( z1um%6CS{4CHLz6)6FQmEwp?#~*OY0$G$J#8nT>uwGVxB7_ooNC^>>gN42k72*QLY< z{N)H_@sbNu>avu@G@6BJ_FW2KW6NTMbA`9Z-QB&tqei<8%*oM`4mr74>uP9yt8vt6 z>?zVAi+X8n0@R8k-|Yd}sJSN`f1XMT2;Y?;f-jdsaxP*2du;!djWwwRAHk=#*u_@3|=|IV-Q#4HI ztxitXvy?QQD29xa_)9@g!4h+o>>l$q1CGkuRWV%@=c?!YIrsGS94g9Y=zL1fvl=Bc ztK-vp^^$mffqD#%g}db`g}u8IOGv?YE^39}-OlCy0PW-3sp8qSNyW1lHSM3{+E-3= zEZj*J!xpvtGIXuqkp{1cQ(^qHw6r9I>LAce30+SJ6@?qV9=IW%p#bOqu45P4;G+4x%^vNxk_{J*OQ*9upz z2mk%b@dMUsxdv&&GkfzFuEapaF|=V}&Uo^(LMop8wvdS@pFr1Vg&FbW-yrZs;r|s+ Nz5-yXtRV3k005~!1XKV3 diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index e193cb9b3..7d446c331 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -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 = { '*': { @@ -176,7 +176,7 @@ 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(', ')})`), ); } @@ -186,6 +186,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; From 83210f6948ba429c8cc37b320b5ae0c0ad6c466b Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 22 Jul 2024 13:21:42 -0400 Subject: [PATCH 2/4] Update changelog and package --- packages/core/CHANGELOG.md | 4 ++++ packages/core/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 96db20f4e..db645383b 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.34.4 (2024-07-22) + +- Fix Hardhat compile error when return parameter names are documented as param. + ## 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)) diff --git a/packages/core/package.json b/packages/core/package.json index 4067f0527..e6f2f99d4 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", From 2ad4b57c26e9f876709b473db886646706fac029 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 22 Jul 2024 13:31:00 -0400 Subject: [PATCH 3/4] lint --- packages/core/src/utils/make-namespaced.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index 7d446c331..4b7b7f97c 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -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((param) => toReturnParameterReplacement(param)).join(', ')})`), + makeReplace( + node.returnParameters, + orig, + `(${node.returnParameters.parameters.map(param => toReturnParameterReplacement(param)).join(', ')})`, + ), ); } From 1048a3c7fed86d295410d57693517f1d7ee60e54 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 22 Jul 2024 13:31:39 -0400 Subject: [PATCH 4/4] Update changelog --- packages/core/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index db645383b..6dfe14330 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.34.4 (2024-07-22) -- Fix Hardhat compile error when return parameter names are documented as param. +- 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)