Просмотр исходного кода

Fix mutability check (#1544)

Fixes #1493

Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
Lucas Steuernagel 2 лет назад
Родитель
Сommit
61aa1ab7a1

+ 3 - 6
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;

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 17 - 0
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

+ 1 - 1
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<String>) {