TVM-Solidity-Compiler
TVM-Solidity-Compiler copied to clipboard
false warning: Function state mutability can be restricted to pure [v0.57.3]
App.sol
pragma ton-solidity = 0.57.3;
contract App {
uint public owner;
modifier onlyOwner() {
require(msg.pubkey() == owner);
_;
}
modifier checkPubKey() {
require(msg.pubkey() == tvm.pubkey());
_;
}
constructor() public checkPubKey {
tvm.accept();
owner = msg.pubkey();
}
function foo(string bar) public view onlyOwner returns(string out) {
tvm.accept();
out = format('42{}', bar);
}
}
npx everdev sol set --compiler 0.57.3
npx everdev sol compile --code --output-dir build App.sol
Warning: Function state mutability can be restricted to pure
--> App.sol:21:5:
|
21 | function foo(string bar) public view onlyOwner returns(string out) {
| ^ (Relevant source part starts here and spans across multiple lines).
Why is it wrong warning?
https://github.com/broxus/ton-contracts/pull/4#issuecomment-1046136377 This method can't be pure because the onlyOwner modifier must have access to the contract state which is not loaded for pure methods. It is a known bug in compiler which still exists. @Rexagon
Hi @IgorKoval ! How's it going? For me, it seems like a critical bug. onlyOwner
is a well-known pattern in Solidity development. Probably every second developer will see the compiler hint and insert the pure
modifier, which leads to unexpected behavior.