1

Could someone explain how this line of code (linked below) properly circumvents the "stack too deep" error? I was under the assumption that the "stack too deep" error meant the method needed to be broken up into smaller sub-methods, as it has too many local variables. Though in the swap method it looks like defining a new block scope gets around that? is this a recommended way to go about doing things?

https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2Pair.sol#L166

2
  • Pretty good way to go around it, yes. Other alternatives you can see here: soliditydeveloper.com/stacktoodeep. Sep 25, 2020 at 7:29
  • Hello and welcome! We usually ask for posters to put a formatted code block of the code they're asking about instead of just a link. (You can format a code block using three backtics, as in Markdown.) The link is great - people who want more context will know where to look. Cheers! Sep 25, 2020 at 8:27

1 Answer 1

4

Without even opening the link:

Scoping a piece of code with { ... } has the same impact as placing that piece of code in a separate function.

This option has become available starting from solc 0.5.0.

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