Solidity
abi.decode() 和未使用的變數
我正在解碼字節如下:
// Decode Solidity tightly packed arguments (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address)); // solhint-disable-line
我收到編譯器警告:
Variable '_' is declared but never used.
什麼是漂亮地抑制這個警告的正確方法?我知道如何對函式參數執行此操作,但不確定使用
abi.decode
.明顯的方法不起作用:
/Users/moo/code/dawn-erc20/contracts/Staking.sol:255:23: ParserError: Expected ',' but got identifier (uint8, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address)); // solhint-disable-line
您也可以在函式呼叫中擺脫它,即:
(uint128 stakeId, address behalf) = abi.decode(userData, (uint128, address));
但我想這只會超出你一開始的目的。
所以想到的最快的解決方法是添加一個虛擬參考:
(uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address)); _; // a dummy reference to an unused local variable