0

If I have a function

function b(address _foo) verifySomeClause {
}

and a modifier that can take different addresses as an argument, so that msg.sender can be one of those,

modifier c(address _foo) {
}

and the function modifier is called like this

function b(address _foo) verifySomeClause(_foo) {
}

and like this,

function b(address _foo) verifySomeClause(msg.sender) {
}

is there any problem with having the same argument name for the modifier and function?

1

No, there are no issues with such a declaration. To understand this, you might want to look into variable scoping which is how Solidity would evaluate the code.

Take a look at the code below:

contract Demo {
    event print(address _foo);

    modifier c (address _foo) {
        emit print(_foo);
        _;
    }
    function b (address _foo) c (msg.sender) {
        emit print(_foo);
    }
}

When you call the function b, take a look at how it will be evaluated. The modifier c will 'extend' the function b, which is what it is supposed to do. But when this call is made, msg.sender already has a value, and you'll supply the value for the argument _foo when calling the function b.

I have added the event print to make it obvious that those are two different variables bound to different variables. If you run the contract and call function b with a value different from the msg.sender, you'd notice that both the values will be emitted in the events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.