intellij-solidity icon indicating copy to clipboard operation
intellij-solidity copied to clipboard

setting a variable within a require statement that is to be returned gives `Return variable not assigned`

Open biddls opened this issue 3 years ago • 1 comments

this is code from here edited a bit by me but i havent touched the line in question. You can see that shares has been set within the require statement but when parsing the code it does not recognise that as an assignment of the variable

// Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
	// Check for rounding error since we round down in previewDeposit.
	require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

	// Need to transfer before minting or ERC777s could reenter.
	asset.transferFrom(msg.sender, address(this), assets);

	foo._mint(receiver, shares);

	emit Deposit(msg.sender, receiver, assets, shares);

	afterDeposit(assets, shares);
}

So I'm wondering that this might have been missed and needs to be added so that it can recognise the assignment

Thanks

biddls avatar Apr 24 '22 12:04 biddls

Hi, @biddls! Thanks, this case might have been missed. For now, you can also disable the inspection completely.

SerCeMan avatar May 01 '22 03:05 SerCeMan

This still happens in version 2.3.11, and the same thing happens with try-catch

interface ITest {
    function test() external;
}

contract Test {
    function testRequire(uint input) external returns (bool result) {
        require((result = input > 0), "input must be greater than 0");
    }

    function testTryCatch() external returns (bool result) {
        try ITest(0x0000000000000000000000000000000000000000).test() {
            result = true;
        } catch {
            result = false;
        }
    }
}

There doesn't seem to be any syntax highlighting for try-catch either:

image

ReflectiveChimp avatar Jan 02 '23 19:01 ReflectiveChimp