Hey there, as I was testing events and errors, I thought the following function is a pure function, however, the compiler issues a TypeError that the line emit ConcatStrings(str1, str2, newString);
potentially modifies the state. I’m wondering why. Thanks.
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.4;
contract Test {
event ConcatStrings(string str1, string str2, string newString);
error EmptyStringsNotAllowed(string str1, string str2);
function concatStrings(string memory str1, string memory str2) public pure returns(string memory) {
if (keccak256(abi.encodePacked(str1)) == keccak256(abi.encodePacked("")) ||
keccak256(abi.encodePacked(str2)) == keccak256(abi.encodePacked(""))) {
revert EmptyStringsNotAllowed(str1, str2);
}
string memory newString = string(abi.encodePacked(str1, str2));
emit ConcatStrings(str1, str2, newString);
return newString;
}
}