Skip to content

Commit

Permalink
Merge pull request #1639 from crytic/no-warn-immut-string
Browse files Browse the repository at this point in the history
do not recommend to make string immutable
  • Loading branch information
montyly authored Feb 14, 2023
2 parents 9997808 + 8475083 commit c2cb22d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
7 changes: 4 additions & 3 deletions slither/detectors/variables/unchanged_state_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def detect(self):
self.constant_candidates.append(v)

elif (
v in constructor_variables_written or v in variables_initialized
) and version.parse(self.compilation_unit.solc_version) >= version.parse(
"0.6.5"
not v.type.is_dynamic
and version.parse(self.compilation_unit.solc_version)
>= version.parse("0.6.5")
and (v in constructor_variables_written or v in variables_initialized)
):
self.immutable_candidates.append(v)
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ contract MyConc{
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
not_constant_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ contract MyConc{
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
not_constant_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) {
constructor(uint b, string memory c) {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ contract Bad {
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
uint should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) {
constructor(uint b, string memory c) {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -49,7 +49,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -90,7 +92,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -115,7 +117,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -156,7 +160,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -181,7 +185,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -222,7 +228,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -247,7 +253,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down

0 comments on commit c2cb22d

Please sign in to comment.