Skip to content

Commit

Permalink
Remove duplicate mutability message
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
  • Loading branch information
LucasSte committed Aug 8, 2023
1 parent cb7a691 commit 4c8695b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/sema/mutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,19 @@ fn read_expression(expr: &Expression, state: &mut StateCheck) -> bool {
| Builtin::Gasprice
| Builtin::GasLimit
| Builtin::MinimumBalance
| Builtin::Balance
| Builtin::Accounts,
| Builtin::Balance,
..
} => state.read(loc),

Expression::Builtin {
loc,
kind: Builtin::Accounts,
..
} => {
state.read(loc);
return false;
}

Expression::Builtin {
loc,
kind: Builtin::PayableSend | Builtin::PayableTransfer | Builtin::SelfDestruct,
Expand Down Expand Up @@ -444,27 +453,25 @@ fn read_expression(expr: &Expression, state: &mut StateCheck) -> bool {
state.write(loc);
}
Expression::ExternalFunctionCall { loc, function, .. }
| Expression::InternalFunctionCall { loc, function, .. } => {
match function.ty() {
Type::ExternalFunction { mutability, .. }
| Type::InternalFunction { mutability, .. } => {
match mutability {
Mutability::Nonpayable(_) | Mutability::Payable(_) => state.write(loc),
Mutability::View(_) => state.read(loc),
Mutability::Pure(_) => (),
};
}
_ => unreachable!(),
| Expression::InternalFunctionCall { loc, function, .. } => match function.ty() {
Type::ExternalFunction { mutability, .. }
| Type::InternalFunction { mutability, .. } => {
match mutability {
Mutability::Nonpayable(_) | Mutability::Payable(_) => state.write(loc),
Mutability::View(_) => state.read(loc),
Mutability::Pure(_) => (),
};
}
return true;
}
_ => unreachable!(),
},
Expression::ExternalFunctionCallRaw { loc, ty, .. } => match ty {
CallTy::Static => state.read(loc),
CallTy::Delegate | CallTy::Regular => state.write(loc),
},
Expression::NamedMember { loc, name, .. } if name == BuiltinAccounts::DataAccount => {
state.read(loc);
state.data_account |= DataAccountUsage::READ;
return false;
}
_ => {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract Foo {
function addr_account() public pure returns (address) {
return tx.accounts.dataAccount.key;
}
}

// ---- Expect: diagnostics ----
// error: 3:16-39: function declared 'pure' but this expression reads from state

0 comments on commit 4c8695b

Please sign in to comment.