2

I've randomly stumbled upon a code where the function uses this; in the end of function

function _preValidatePurchase(address beneficiary, uint256 weiAmount) internal view {
        require(beneficiary != address(0), "Crowdsale: beneficiary is the zero address");
        require(weiAmount != 0, "Crowdsale: weiAmount is 0");
        require(weiAmount >= minPurchase, 'have to send at least: minPurchase');
        require(_contributions[beneficiary].add(weiAmount)<= maxPurchase, 'can\'t buy more than: maxPurchase');
        require((_weiRaised+weiAmount) <= hardCap, 'Hard Cap reached');
        this; //What is the purpose of using this; here
    } 

In last where this; is used what is the purpose of using this, as far as i know this keyword refers to current instance but what purpose does it serve there?

Saad Suri
  • 89
  • 6

1 Answers1

4

It is a way of telling the compiler to silent unwanted warnings. If there wasn't this keyword, the compiler would have said state mutability can be restricted to pure, which is not necessarily true for the contracts that might override this function and read the state variables.

See for more:

Emrah
  • 1,654
  • 2
  • 9
  • 24