Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing of Try/Catch syntax #914

Closed
Thomas-Sciaroni opened this issue Aug 14, 2021 · 2 comments
Closed

Incorrect parsing of Try/Catch syntax #914

Thomas-Sciaroni opened this issue Aug 14, 2021 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@Thomas-Sciaroni
Copy link

The detectors do not understand that the try block declares a variable, initializes it to the return value of the called function, and then makes it available in the try scope.

// SPDX-License-Identifier: unlicensed

pragma solidity ^0.8.0;

interface IContract {
    function foo() external returns (uint256);
}

contract Test {
    function test(address _contractAddress) external {
        IContract _contract = IContract(_contractAddress);
        try _contract.foo() returns (uint256 bar) {
            uint256 x = bar;
        } catch {
            revert("Contract does not implement foo()");
        }
    }
}
INFO:Detectors:
Test.test(address).bar (contracts/LiquidityOcean/Test.sol#12) is a local variable never initialized
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#uninitialized-local-variables
INFO:Detectors:
Test.test(address) (contracts/LiquidityOcean/Test.sol#10-17) ignores return value by _contract.foo() (contracts/LiquidityOcean/Test.sol#12-16)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#unused-return
INFO:Detectors:
Variable 'Test.test(address).bar (contracts/LiquidityOcean/Test.sol#12)' in Test.test(address) (contracts/LiquidityOcean/Test.sol#10-17) potentially used before declaration: x = bar (contracts/LiquidityOcean/Test.sol#13)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#pre-declaration-usage-of-local-variables
@montyly
Copy link
Member

montyly commented Aug 16, 2021

I @Thomas-Sciaroni . Thank you for reporting this.

We are aware of the incorrect parsing of the try/catch syntax, and will improve it (related: #511)

@montyly montyly added bug Something isn't working enhancement New feature or request labels Aug 16, 2021
@0xmichalis
Copy link

Also duplicate of #982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants