Help fixing 'Stack too deep' error in Solidity?

Hi Everyone, I keep getting the ‘stack too deep’ error on solidity with this code. I was wondering if anyone can help me fix this. Any help would be greatly appreciated.

function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
        uint256 tFee = calculateTaxFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tDev = calculateDevFee(tAmount);
        uint256 tBurn = calculateBurnFee(tAmount);
        uint256 tCharity = calculateCharityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
                tTransferAmount = tTransferAmount.sub(tDev);
                tTransferAmount = tTransferAmount.sub(tCharity);
                tTransferAmount = tTransferAmount.sub(tBurn);

        return (tTransferAmount, tFee, tLiquidity, tDev, tBurn, tCharity);
    }

Asked @nventuro and he suggested to try using named return values:

function _getTValues(uint256 tAmount) private view returns (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tDev, uint256 tBurn, uint256 tCharity) {
    tFee = calculateTaxFee(tAmount);
    tLiquidity = calculateLiquidityFee(tAmount);
    tDev = calculateDevFee(tAmount);
    tBurn = calculateBurnFee(tAmount);
    tCharity = calculateCharityFee(tAmount);
    tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
    tTransferAmount = tTransferAmount.sub(tDev);
    tTransferAmount = tTransferAmount.sub(tCharity);
    tTransferAmount = tTransferAmount.sub(tBurn);
}
3 Likes

Thank you! It worked perfectly.

1 Like