Dasselbe Problem wird hier diskutiert, kam aber zu keinem Ergebnis.
Ich denke, das passiert wegen des new
Schlüsselworts beim Erstellen von variable string abcde
.
Ich habe zwei Beispielverträge für die Bestätigung ausprobiert.
pragma solidity ^0.4.24;
contract Foo {
uint256 n = 10;
function initArray() public view {
uint[10*10] memory result;
for (uint i = 0; i < n; i++){
for(uint j = 0; j < n; j++){
result[(i*9)+j]=1;
}
}
}
}
Für den obigen Smart Contract gibt Remix keine Warnung aus Is constant but potentially should not be
.
pragma solidity ^0.4.24;
contract Foo {
uint256 n = 10;
function initArray() public view {
uint[] memory result = new uint[](n*n);
for (uint i = 0; i < n; i++){
for(uint j = 0; j < n; j++){
result[(i*9)+j]=1;
}
}
}
}
Für den obigen Kontrakt-Remix wirft jedoch die Warnung aus:Is constant but potentially should not be.
Die Funktion schreibt in eine an anderer Stelle definierte Zustandsvariable babcde[]
. Da es in den Zustand schreibt, ist der schreibgeschützte pure
Modifikator wahrscheinlich fehlerhaft.
Ich hoffe es hilft.