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

uma
  • 13
  • 2
  • Pretty good way to go around it, yes. Other alternatives you can see here: https://soliditydeveloper.com/stacktoodeep. – Markus - soliditydeveloper.com Sep 25 '20 at 07: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! – The Renaissance Sep 25 '20 at 08:27

1 Answers1

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.

goodvibration
  • 26,003
  • 5
  • 46
  • 86