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

False positive for unused-return #115

Closed
mrice32 opened this issue Dec 22, 2018 · 2 comments
Closed

False positive for unused-return #115

mrice32 opened this issue Dec 22, 2018 · 2 comments

Comments

@mrice32
Copy link
Contributor

mrice32 commented Dec 22, 2018

Sorry for posting so many false positives, but this was the last one we found in our codebase that seemed to be erroneous. The unused-return detector seems to be tricked when using a ternary that calls a function inside a return statement. Since it seems that all three of those conditions must be true to trigger the erroneous detection, this seems like an edge case that can easily be avoided by slightly changing the syntax. Still, I thought it was worth creating a dummy example to demonstrate it:

/*
  Test
*/
pragma solidity ^0.5.0;


library Math {
    function add(uint a, uint b) internal pure returns (uint c) {
        c = a + b;
    }

    function sub(uint a, uint b) internal pure returns (uint c) {
        c = a - b;
    }
}


contract TestContract {
    using Math for uint;

    uint public value;

    constructor() public {
        value = 0;
    }

    function updateValue(bool isAdd) external {
        value = getUpdatedValue(isAdd);
    }

    function getUpdatedValue(bool isAdd) public view returns (uint) {
        return isAdd ? value.add(1) : value.sub(1);
    }
}
@dguido
Copy link
Member

dguido commented Dec 22, 2018

This is great, thank you! Drop by our Slack and say hello: https://empireslacking.herokuapp.com/

@montyly
Copy link
Member

montyly commented Dec 23, 2018

Hi @mrice32 , thank for the minimal testcase!

It is fixed in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants