diff --git a/src/sema/mutability.rs b/src/sema/mutability.rs index 78f4ec065..88138877e 100644 --- a/src/sema/mutability.rs +++ b/src/sema/mutability.rs @@ -367,7 +367,7 @@ fn read_expression(expr: &Expression, state: &mut StateCheck) -> bool { left.recurse(state, write_expression); return false; } - Expression::StorageArrayLength { loc, .. } | Expression::StorageLoad { loc, .. } => { + Expression::StorageArrayLength { loc, .. } => { state.data_account |= DataAccountUsage::READ; state.read(loc); return false; @@ -375,12 +375,9 @@ fn read_expression(expr: &Expression, state: &mut StateCheck) -> bool { Expression::Subscript { loc, array_ty, .. } if array_ty.is_contract_storage() => { state.data_account |= DataAccountUsage::READ; state.read(loc); - return false; } - Expression::Variable { ty, .. } => { - if ty.is_contract_storage() { - state.data_account |= DataAccountUsage::READ; - } + Expression::Variable { ty, .. } if ty.is_contract_storage() => { + state.data_account |= DataAccountUsage::READ; } Expression::StorageVariable { loc, .. } => { state.data_account |= DataAccountUsage::READ; diff --git a/tests/contract_testcases/polkadot/functions/global_functions_07.sol b/tests/contract_testcases/polkadot/functions/global_functions_07.sol index 88aa6ab26..3d2eeb769 100644 --- a/tests/contract_testcases/polkadot/functions/global_functions_07.sol +++ b/tests/contract_testcases/polkadot/functions/global_functions_07.sol @@ -4,4 +4,4 @@ // ---- Expect: diagnostics ---- // warning: 2:34-35: declaration of 'x' shadows function // note 2:18-19: previous declaration of function -// error: 2:58-69: function declared 'pure' but this expression reads from state +// error: 2:65-69: function declared 'pure' but this expression reads from state diff --git a/tests/contract_testcases/polkadot/functions/mutability.sol b/tests/contract_testcases/polkadot/functions/mutability.sol index 90b2ce3f2..ff65f3fcc 100644 --- a/tests/contract_testcases/polkadot/functions/mutability.sol +++ b/tests/contract_testcases/polkadot/functions/mutability.sol @@ -6,4 +6,4 @@ contract test { } } // ---- Expect: diagnostics ---- -// error: 5:17-27: function declared 'pure' but this expression reads from state +// error: 5:24-27: function declared 'pure' but this expression reads from state diff --git a/tests/contract_testcases/polkadot/functions/mutability_02.sol b/tests/contract_testcases/polkadot/functions/mutability_02.sol index ef0436ee5..364ed07c4 100644 --- a/tests/contract_testcases/polkadot/functions/mutability_02.sol +++ b/tests/contract_testcases/polkadot/functions/mutability_02.sol @@ -4,4 +4,4 @@ abstract contract test { } } // ---- Expect: diagnostics ---- -// error: 3:17-30: function declared 'pure' but this expression reads from state +// error: 3:24-30: function declared 'pure' but this expression reads from state diff --git a/tests/contract_testcases/solana/functions/mutability.sol b/tests/contract_testcases/solana/functions/mutability.sol new file mode 100644 index 000000000..5bc400a1a --- /dev/null +++ b/tests/contract_testcases/solana/functions/mutability.sol @@ -0,0 +1,17 @@ +contract C { + bool x; + int[4] a; + + function test() public view returns (int) { + return foo()[1]; + } + + function foo() internal returns (int[4] storage) { + x = true; + return a; + } + +} + +// ---- Expect: diagnostics ---- +// error: 6:10-15: function declared 'view' but this expression writes to state \ No newline at end of file diff --git a/tests/evm.rs b/tests/evm.rs index 8f5f30187..21ae43539 100644 --- a/tests/evm.rs +++ b/tests/evm.rs @@ -249,7 +249,7 @@ fn ethereum_solidity_tests() { }) .sum(); - assert_eq!(errors, 1030); + assert_eq!(errors, 1029); } fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec) {