5

I am decoding bytes as the following:

      // Decode Solidity tightly packed arguments
      (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));  // solhint-disable-line

I get a compiler warning:

Variable '_' is declared but never used.

What would be the right way to suppress this warning beautifully? I know how to do this for function arguments, but not sure how what is a good practice with abi.decode.

The obvious way does not work:

/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
1
  • 3
    Why not (, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));
    – hrkrshnn
    Jul 26, 2020 at 18:28

2 Answers 2

2

You could get rid of it in the function-call as well, i.e.:

(uint128 stakeId, address behalf) = abi.decode(userData, (uint128, address));

But I suppose that would just beat your purpose to begin with.

So the quickest workaround which comes to mind is to just add a dummy reference:

(uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));
_; // a dummy reference to an unused local variable
2
  • this "obvious" way does not work - see the updated question. Apr 6, 2020 at 15:23
  • @MikkoOhtamaa: See updated answer. Apr 6, 2020 at 15:41
5
(, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));

Try this, it should work ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.