From 0feb8625fd49ab532d1d6622ab06612396ab7987 Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Mon, 4 Apr 2022 14:44:56 -0700 Subject: [PATCH] wip --- crates/analyzer/src/context.rs | 2 +- crates/analyzer/src/db/queries/functions.rs | 9 +- crates/analyzer/src/namespace/scopes.rs | 6 +- crates/analyzer/src/namespace/types.rs | 9 +- crates/analyzer/src/traversal/assignments.rs | 24 +- crates/analyzer/src/traversal/expressions.rs | 71 ++++-- .../analysis__abi_encoding_stress.snap | 91 +++++--- .../analysis__address_bytes10_map.snap | 14 +- .../tests/snapshots/analysis__assert.snap | 14 +- .../snapshots/analysis__associated_fns.snap | 7 +- .../tests/snapshots/analysis__aug_assign.snap | 7 +- .../tests/snapshots/analysis__balances.snap | 14 +- .../analysis__call_statement_with_args.snap | 14 +- .../analysis__call_statement_with_args_2.snap | 14 +- ...analysis__call_statement_without_args.snap | 14 +- .../snapshots/analysis__constructor.snap | 7 +- .../analysis__create_contract_from_init.snap | 7 +- .../analysis__data_copying_stress.snap | 42 +++- .../snapshots/analysis__erc20_token.snap | 112 ++++++--- .../tests/snapshots/analysis__guest_book.snap | 14 +- .../tests/snapshots/analysis__nested_map.snap | 28 ++- .../tests/snapshots/analysis__ownable.snap | 21 +- .../analysis__pure_fn_standalone.snap | 14 +- .../analysis__return_u256_from_called_fn.snap | 7 +- ..._return_u256_from_called_fn_with_args.snap | 7 +- .../tests/snapshots/analysis__revert.snap | 7 +- .../analysis__sized_vals_in_sto.snap | 49 ++-- .../tests/snapshots/analysis__struct_fns.snap | 35 ++- .../tests/snapshots/analysis__structs.snap | 70 ++++-- .../snapshots/analysis__tuple_stress.snap | 21 +- .../snapshots/analysis__two_contracts.snap | 23 +- .../snapshots/analysis__type_aliases.snap | 25 +- .../snapshots/analysis__u128_u128_map.snap | 14 +- .../snapshots/analysis__u16_u16_map.snap | 14 +- .../snapshots/analysis__u256_u256_map.snap | 14 +- .../snapshots/analysis__u32_u32_map.snap | 14 +- .../snapshots/analysis__u64_u64_map.snap | 14 +- .../tests/snapshots/analysis__u8_u8_map.snap | 14 +- .../tests/snapshots/analysis__uniswap.snap | 218 ++++++++++++------ .../errors__assign_type_mismatch.snap | 2 +- ..._call_non_pub_fn_on_external_contract.snap | 8 + .../errors__ctx_missing_internal_call.snap | 8 + .../errors__ctx_passed_external_call.snap | 9 + .../snapshots/errors__missing_return.snap | 8 + .../tests/snapshots/errors__self_misuse.snap | 8 + .../snapshots/errors__self_mut_mismatch.snap | 25 +- crates/test-files/fixtures/demos/uniswap.fe | 40 ++-- .../fixtures/features/two_contracts.fe | 4 +- .../fixtures/features/type_aliases.fe | 4 +- 49 files changed, 869 insertions(+), 348 deletions(-) diff --git a/crates/analyzer/src/context.rs b/crates/analyzer/src/context.rs index f59b8cea4e..420b477340 100644 --- a/crates/analyzer/src/context.rs +++ b/crates/analyzer/src/context.rs @@ -223,7 +223,7 @@ pub enum NamedThing { }, // SelfType // when/if we add a `Self` type keyword Variable { - name: String, + name: SmolStr, typ: Result, mutability: BindingMutability, span: Span, diff --git a/crates/analyzer/src/db/queries/functions.rs b/crates/analyzer/src/db/queries/functions.rs index 29048e47f7..aa7280c2b3 100644 --- a/crates/analyzer/src/db/queries/functions.rs +++ b/crates/analyzer/src/db/queries/functions.rs @@ -5,7 +5,9 @@ use crate::namespace::items::{ Class, DepGraph, DepGraphWrapper, DepLocality, FunctionId, Item, TypeDef, }; use crate::namespace::scopes::{BlockScope, BlockScopeType, FunctionScope, ItemScope}; -use crate::namespace::types::{self, Contract, CtxDecl, FixedSize, SelfDecl, Struct, Type}; +use crate::namespace::types::{ + self, Contract, CtxDecl, FixedSize, SelfDecl, SelfDeclKind, Struct, Type, +}; use crate::traversal::functions::traverse_statements; use crate::traversal::types::type_desc; use fe_common::diagnostics::Label; @@ -56,7 +58,10 @@ pub fn function_signature( "not allowed in functions defined outside of a contract or struct", ); } else { - self_decl = Some(if mut_.is_some() { SelfDecl::MutRef } else { SelfDecl::Ref }); + self_decl = Some(SelfDecl { + kind: if mut_.is_some() { SelfDeclKind::MutRef } else { SelfDeclKind::Ref }, + span: arg.span, + }); if index != 0 { scope.error( "`self` is not the first parameter", diff --git a/crates/analyzer/src/namespace/scopes.rs b/crates/analyzer/src/namespace/scopes.rs index eb557af3cd..fd071bd684 100644 --- a/crates/analyzer/src/namespace/scopes.rs +++ b/crates/analyzer/src/namespace/scopes.rs @@ -115,6 +115,8 @@ impl<'a> AnalyzerContext for ItemScope<'a> { fn resolve_name(&self, name: &str, span: Span) -> Result, IncompleteItem> { let item = self.module.resolve_name(self.db, name)?; + // TODO: do this somewhere else, so name resolution can be attempted + // without emitting an error if let Some(item) = item { check_item_visibility(self, item, span); } @@ -332,7 +334,7 @@ impl<'a> AnalyzerContext for FunctionScope<'a> { .expect("found param type but not span"); NamedThing::Variable { - name: name.to_string(), + name: name.into(), typ: param.typ.clone(), mutability: if param.is_mut { BindingMutability::Mutable @@ -417,7 +419,7 @@ impl AnalyzerContext for BlockScope<'_, '_> { self.variable_defs .get(name) .map(|(typ, mutability, span)| NamedThing::Variable { - name: name.to_string(), + name: name.into(), typ: Ok(typ.clone()), mutability: *mutability, span: *span, diff --git a/crates/analyzer/src/namespace/types.rs b/crates/analyzer/src/namespace/types.rs index 8f95850ebd..ad3113f595 100644 --- a/crates/analyzer/src/namespace/types.rs +++ b/crates/analyzer/src/namespace/types.rs @@ -162,8 +162,13 @@ pub struct FunctionSignature { pub return_type: Result, } -#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] -pub enum SelfDecl { +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub struct SelfDecl { + pub kind: SelfDeclKind, + pub span: Span, +} +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub enum SelfDeclKind { Ref, MutRef, // Value diff --git a/crates/analyzer/src/traversal/assignments.rs b/crates/analyzer/src/traversal/assignments.rs index 824e4856ff..885d67f6a2 100644 --- a/crates/analyzer/src/traversal/assignments.rs +++ b/crates/analyzer/src/traversal/assignments.rs @@ -6,7 +6,8 @@ use crate::traversal::expressions; use crate::traversal::utils::add_bin_operations_errors; use fe_common::diagnostics::Label; use fe_parser::ast as fe; -use fe_parser::node::Node; +use fe_parser::node::{Node, Span}; +use smol_str::SmolStr; /// Gather context information for assignments and check for type errors. /// @@ -70,14 +71,31 @@ pub fn assign(scope: &mut BlockScope, stmt: &Node) -> Result<(), F Ok(()) } +fn find_name_def(scope: &BlockScope, expr: &Node) -> Option<(SmolStr, Span)> { + match &expr.kind { + fe::Expr::Attribute { value, .. } | fe::Expr::Subscript { value, .. } => { + find_name_def(scope, &value) + } + fe::Expr::Name(name) => { + let thing = scope.resolve_name(&name, expr.span).ok()??; + thing.name_span(scope.db()).map(|span| (name.clone(), span)) + } + _ => None, + } +} + fn check_assign_target(scope: &mut BlockScope, target: &Node) -> Result<(), FatalError> { use fe::Expr::*; match &target.kind { Attribute { value: container, .. } | Subscript { value: container, .. } => { if !scope.expr_is_mutable(&container) { - scope.fancy_error("immutable", // XXX better error - vec![Label::primary(container.span, "")], + let mut labels = vec![Label::primary(container.span, "not mutable")]; + if let Some((name, span)) = find_name_def(scope, container) { + labels.push(Label::secondary(span, &format!("consider changing this to be mutable: `mut {}`", name))); + } + scope.fancy_error(&format!("cannot modify `{}`, as it is not mutable", &container.kind), + labels, vec![]); } // XXX diff --git a/crates/analyzer/src/traversal/expressions.rs b/crates/analyzer/src/traversal/expressions.rs index 572c10f3ac..eddfc40e4d 100644 --- a/crates/analyzer/src/traversal/expressions.rs +++ b/crates/analyzer/src/traversal/expressions.rs @@ -6,7 +6,8 @@ use crate::errors::{FatalError, IndexingError, NotFixedSize}; use crate::namespace::items::{Class, FunctionId, Item, TypeDef}; use crate::namespace::scopes::BlockScopeType; use crate::namespace::types::{ - Array, Base, Contract, FeString, Integer, SelfDecl, Struct, Tuple, Type, TypeDowncast, U256, + Array, Base, Contract, FeString, Integer, SelfDecl, SelfDeclKind, Struct, Tuple, Type, + TypeDowncast, U256, }; use crate::operations; use crate::traversal::call_args::{validate_arg_count, validate_named_args}; @@ -65,16 +66,14 @@ pub fn expr_list( expected_type: Option<&Array>, ) -> Result { if elts.is_empty() { - return Ok(ExpressionAttributes { - typ: Type::Array(Array { + return Ok(ExpressionAttributes::new( + Type::Array(Array { size: 0, inner: expected_type.map_or(Base::Unit, |arr| arr.inner), }), - location: Location::Memory, - move_location: None, - const_value: None, - mutable: false, // XXX - }); + Location::Memory, + true, + )); } let inner_type = if let Some(expected) = expected_type { @@ -135,13 +134,11 @@ pub fn expr_list( inner: inner_type, }; - Ok(ExpressionAttributes { - typ: Type::Array(array_typ), - location: Location::Memory, - move_location: None, - const_value: None, - mutable: false, // XXX - }) + Ok(ExpressionAttributes::new( + Type::Array(array_typ), + Location::Memory, + true, + )) } /// Gather context information for expressions and check for type errors. @@ -331,7 +328,13 @@ fn expr_named_thing( }, ); } - let mutable = decl == Some(SelfDecl::MutRef); + let mutable = matches!( + decl, + Some(SelfDecl { + kind: SelfDeclKind::MutRef, + .. + }) + ); let (typ, location) = match class { Class::Struct(id) => ( Type::Struct(Struct::from_id(id, context.db())), @@ -1413,13 +1416,30 @@ fn expr_call_method( )], ); } - Some(SelfDecl::MutRef) => { - if context.parent_function().self_decl(context.db()) == Some(SelfDecl::Ref) + Some(SelfDecl { + kind: SelfDeclKind::MutRef, + .. + }) => { + if let Some(SelfDecl { + kind: SelfDeclKind::Ref, + span, + }) = context.parent_function().self_decl(context.db()) { context.fancy_error( - // XXX better error message - "bad call to mut self fn", - vec![Label::primary(field.span, "function requires mut self")], + &format!( + "function `{}` requires `mut self`", + method.name(context.db()) + ), + vec![ + Label::primary(field.span, "requires `mut self`"), + Label::secondary(target.span, "not mutable"), + Label::secondary( + span, + &format!( + "consider changing this to be mutable: `mut self`" + ), + ), + ], vec![], ); } @@ -1515,7 +1535,14 @@ fn expr_call_method( // This should be improved when we add explicit references. let self_decl = method.self_decl(context.db()); let mutable = !return_type.is_base() - && !(matches!(class, Class::Struct(_)) && self_decl == Some(SelfDecl::Ref)); + && !(matches!(class, Class::Struct(_)) + && matches!( + self_decl, + Some(SelfDecl { + kind: SelfDeclKind::Ref, + .. + }) + )); return Ok(( ExpressionAttributes::new(return_type.into(), location, mutable), diff --git a/crates/analyzer/tests/snapshots/analysis__abi_encoding_stress.snap b/crates/analyzer/tests/snapshots/analysis__abi_encoding_stress.snap index 62ea620230..abd5a42df4 100644 --- a/crates/analyzer/tests/snapshots/analysis__abi_encoding_stress.snap +++ b/crates/analyzer/tests/snapshots/analysis__abi_encoding_stress.snap @@ -52,11 +52,14 @@ note: │ 25 │ ╭ pub fn set_my_addrs(mut self, my_addrs: Array): 26 │ │ self.my_addrs = my_addrs - │ ╰────────────────────────────────^ attributes hash: 692741412233121018 + │ ╰────────────────────────────────^ attributes hash: 11907551293737092891 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 524..528, + }, ), ctx_decl: None, params: [ @@ -100,11 +103,14 @@ note: │ 28 │ ╭ pub fn get_my_addrs(self) -> Array: 29 │ │ return self.my_addrs.to_mem() - │ ╰─────────────────────────────────────^ attributes hash: 16639787143458391927 + │ ╰─────────────────────────────────────^ attributes hash: 8952955139640844443 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 618..622, + }, ), ctx_decl: None, params: [], @@ -141,11 +147,14 @@ note: │ 31 │ ╭ pub fn set_my_u128(mut self, my_u128: u128): 32 │ │ self.my_u128 = my_u128 - │ ╰──────────────────────────────^ attributes hash: 15174439713398944677 + │ ╰──────────────────────────────^ attributes hash: 5597635916944040867 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 712..716, + }, ), ctx_decl: None, params: [ @@ -188,11 +197,14 @@ note: │ 34 │ ╭ pub fn get_my_u128(self) -> u128: 35 │ │ return self.my_u128 - │ ╰───────────────────────────^ attributes hash: 17880153799218319458 + │ ╰───────────────────────────^ attributes hash: 5900314040552767476 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 789..793, + }, ), ctx_decl: None, params: [], @@ -222,11 +234,14 @@ note: │ 37 │ ╭ pub fn set_my_string(mut self, my_string: String<10>): 38 │ │ self.my_string = my_string - │ ╰──────────────────────────────────^ attributes hash: 12300516031968723157 + │ ╰──────────────────────────────────^ attributes hash: 17153493147100377446 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 862..866, + }, ), ctx_decl: None, params: [ @@ -269,11 +284,14 @@ note: │ 40 │ ╭ pub fn get_my_string(self) -> String<10>: 41 │ │ return self.my_string.to_mem() - │ ╰──────────────────────────────────────^ attributes hash: 10620799605687412147 + │ ╰──────────────────────────────────────^ attributes hash: 18269957818831288458 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 953..957, + }, ), ctx_decl: None, params: [], @@ -309,11 +327,14 @@ note: │ 43 │ ╭ pub fn set_my_u16s(mut self, my_u16s: Array): 44 │ │ self.my_u16s = my_u16s - │ ╰──────────────────────────────^ attributes hash: 5498232312827445050 + │ ╰──────────────────────────────^ attributes hash: 14514830060010273341 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1041..1045, + }, ), ctx_decl: None, params: [ @@ -359,11 +380,14 @@ note: │ 46 │ ╭ pub fn get_my_u16s(self) -> Array: 47 │ │ return self.my_u16s.to_mem() - │ ╰────────────────────────────────────^ attributes hash: 10782227792912651668 + │ ╰────────────────────────────────────^ attributes hash: 6745623453410200946 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1129..1133, + }, ), ctx_decl: None, params: [], @@ -402,11 +426,14 @@ note: │ 49 │ ╭ pub fn set_my_bool(mut self, my_bool: bool): 50 │ │ self.my_bool = my_bool - │ ╰──────────────────────────────^ attributes hash: 8550003964212154251 + │ ╰──────────────────────────────^ attributes hash: 11446628009684968135 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1220..1224, + }, ), ctx_decl: None, params: [ @@ -447,11 +474,14 @@ note: │ 52 │ ╭ pub fn get_my_bool(self) -> bool: 53 │ │ return self.my_bool - │ ╰───────────────────────────^ attributes hash: 16330752953215905811 + │ ╰───────────────────────────^ attributes hash: 1294024780035271686 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1297..1301, + }, ), ctx_decl: None, params: [], @@ -479,11 +509,14 @@ note: │ 55 │ ╭ pub fn set_my_bytes(mut self, my_bytes: Array): 56 │ │ self.my_bytes = my_bytes - │ ╰────────────────────────────────^ attributes hash: 7925946101508687528 + │ ╰────────────────────────────────^ attributes hash: 5060723730989519036 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1369..1373, + }, ), ctx_decl: None, params: [ @@ -529,11 +562,14 @@ note: │ 58 │ ╭ pub fn get_my_bytes(self) -> Array: 59 │ │ return self.my_bytes.to_mem() - │ ╰─────────────────────────────────────^ attributes hash: 13531926216604903442 + │ ╰─────────────────────────────────────^ attributes hash: 3222210725235203691 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1460..1464, + }, ), ctx_decl: None, params: [], @@ -736,11 +772,14 @@ note: · │ 84 │ │ my_bytes: self.my_bytes.to_mem() 85 │ │ ) - │ ╰─────────^ attributes hash: 17228436346762880410 + │ ╰─────────^ attributes hash: 15495621399908028040 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1978..1982, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/analysis__address_bytes10_map.snap b/crates/analyzer/tests/snapshots/analysis__address_bytes10_map.snap index 6ce4aca1ef..83bf7ede5b 100644 --- a/crates/analyzer/tests/snapshots/analysis__address_bytes10_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__address_bytes10_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: address) -> Array: 5 │ │ return self.bar[key].to_mem() - │ ╰─────────────────────────────────────^ attributes hash: 136125591750325430 + │ ╰─────────────────────────────────────^ attributes hash: 9068490252365331945 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 72..76, + }, ), ctx_decl: None, params: [ @@ -76,11 +79,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: address, value: Array): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 1869503825112297318 + │ ╰─────────────────────────────^ attributes hash: 13667059804977461079 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 174..178, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__assert.snap b/crates/analyzer/tests/snapshots/analysis__assert.snap index 7609afb0b0..e76e831aa9 100644 --- a/crates/analyzer/tests/snapshots/analysis__assert.snap +++ b/crates/analyzer/tests/snapshots/analysis__assert.snap @@ -168,11 +168,14 @@ note: 14 │ ╭ pub fn assert_sto_bool(mut self): 15 │ │ self.my_bool = false 16 │ │ assert self.my_bool - │ ╰───────────────────────────^ attributes hash: 17189319825533802105 + │ ╰───────────────────────────^ attributes hash: 6693705368235761208 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 331..335, + }, ), ctx_decl: None, params: [], @@ -211,11 +214,14 @@ note: 18 │ ╭ pub fn assert_sto_string_msg(mut self): 19 │ │ self.my_string = "hello" 20 │ │ assert false, self.my_string.to_mem() - │ ╰─────────────────────────────────────────────^ attributes hash: 17189319825533802105 + │ ╰─────────────────────────────────────────────^ attributes hash: 3568007169960548949 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 433..437, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__associated_fns.snap b/crates/analyzer/tests/snapshots/analysis__associated_fns.snap index 50b9e0d9c4..ede30998e1 100644 --- a/crates/analyzer/tests/snapshots/analysis__associated_fns.snap +++ b/crates/analyzer/tests/snapshots/analysis__associated_fns.snap @@ -114,11 +114,14 @@ note: 14 │ ╭ pub fn bar(mut self, val: u256) -> u256: 15 │ │ self.my_struct = MyStruct.new(val) 16 │ │ return Lib.square(self.my_struct.x) - │ ╰───────────────────────────────────────^ attributes hash: 11770346170450765250 + │ ╰───────────────────────────────────────^ attributes hash: 3513515857440565468 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 241..245, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__aug_assign.snap b/crates/analyzer/tests/snapshots/analysis__aug_assign.snap index 2454399350..7e9823c1c9 100644 --- a/crates/analyzer/tests/snapshots/analysis__aug_assign.snap +++ b/crates/analyzer/tests/snapshots/analysis__aug_assign.snap @@ -632,11 +632,14 @@ note: 49 │ │ self.my_num = a 50 │ │ self.my_num += b 51 │ │ return self.my_num - │ ╰──────────────────────────^ attributes hash: 1389946720597652 + │ ╰──────────────────────────^ attributes hash: 13558403251906603012 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 919..923, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__balances.snap b/crates/analyzer/tests/snapshots/analysis__balances.snap index bf81decb74..f3ed8f2162 100644 --- a/crates/analyzer/tests/snapshots/analysis__balances.snap +++ b/crates/analyzer/tests/snapshots/analysis__balances.snap @@ -8,11 +8,14 @@ note: │ 5 │ ╭ pub fn my_balance(self, ctx: Context) -> u256: 6 │ │ return ctx.self_balance() - │ ╰─────────────────────────────────^ attributes hash: 9380543137829531562 + │ ╰─────────────────────────────────^ attributes hash: 13707878651479164130 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 99..103, + }, ), ctx_decl: Some( Mutable, @@ -58,11 +61,14 @@ note: │ 8 │ ╭ pub fn other_balance(self, ctx: Context, someone: address) -> u256: 9 │ │ return ctx.balance_of(someone) - │ ╰──────────────────────────────────────^ attributes hash: 6756407878168683139 + │ ╰──────────────────────────────────────^ attributes hash: 5856896025733365099 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 188..192, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/analysis__call_statement_with_args.snap b/crates/analyzer/tests/snapshots/analysis__call_statement_with_args.snap index 0f9fda62b7..4f2712025c 100644 --- a/crates/analyzer/tests/snapshots/analysis__call_statement_with_args.snap +++ b/crates/analyzer/tests/snapshots/analysis__call_statement_with_args.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ fn assign(mut self, _ val: u256): 5 │ │ self.baz[0] = val - │ ╰─────────────────────────^ attributes hash: 15439840318216087573 + │ ╰─────────────────────────^ attributes hash: 6297254016644966608 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 58..62, + }, ), ctx_decl: None, params: [ @@ -72,11 +75,14 @@ note: 7 │ ╭ pub fn bar(mut self) -> u256: 8 │ │ self.assign(100) 9 │ │ return self.baz[0] - │ ╰──────────────────────────^ attributes hash: 14378415039933113528 + │ ╰──────────────────────────^ attributes hash: 6031468977524375017 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 124..128, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__call_statement_with_args_2.snap b/crates/analyzer/tests/snapshots/analysis__call_statement_with_args_2.snap index 638e55bc66..145c6ec4e5 100644 --- a/crates/analyzer/tests/snapshots/analysis__call_statement_with_args_2.snap +++ b/crates/analyzer/tests/snapshots/analysis__call_statement_with_args_2.snap @@ -15,11 +15,14 @@ note: 4 │ ╭ fn assign(mut self, _ val: u256) -> u256: 5 │ │ self.baz[0] = val 6 │ │ return val - │ ╰──────────────────^ attributes hash: 13198797278653585185 + │ ╰──────────────────^ attributes hash: 15151290598141713437 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 58..62, + }, ), ctx_decl: None, params: [ @@ -77,11 +80,14 @@ note: 8 │ ╭ pub fn bar(mut self) -> u256: 9 │ │ self.assign(100) 10 │ │ return self.baz[0] - │ ╰──────────────────────────^ attributes hash: 14378415039933113528 + │ ╰──────────────────────────^ attributes hash: 1705867221757528362 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 151..155, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__call_statement_without_args.snap b/crates/analyzer/tests/snapshots/analysis__call_statement_without_args.snap index 2a9dbdce8f..548dee7ce2 100644 --- a/crates/analyzer/tests/snapshots/analysis__call_statement_without_args.snap +++ b/crates/analyzer/tests/snapshots/analysis__call_statement_without_args.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ fn assign(mut self): 5 │ │ self.baz[0] = 100 - │ ╰─────────────────────────^ attributes hash: 17189319825533802105 + │ ╰─────────────────────────^ attributes hash: 15881511943781534304 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 58..62, + }, ), ctx_decl: None, params: [], @@ -57,11 +60,14 @@ note: 7 │ ╭ pub fn bar(mut self) -> u256: 8 │ │ self.assign() 9 │ │ return self.baz[0] - │ ╰──────────────────────────^ attributes hash: 14378415039933113528 + │ ╰──────────────────────────^ attributes hash: 10386034588617124870 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 111..115, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__constructor.snap b/crates/analyzer/tests/snapshots/analysis__constructor.snap index 77d480717d..be29eae615 100644 --- a/crates/analyzer/tests/snapshots/analysis__constructor.snap +++ b/crates/analyzer/tests/snapshots/analysis__constructor.snap @@ -14,11 +14,14 @@ note: │ 7 │ ╭ pub fn read_bar(self) -> u256: 8 │ │ return self.bar[42] - │ ╰───────────────────────────^ attributes hash: 9289100627868228400 + │ ╰───────────────────────────^ attributes hash: 4829092069121301109 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 149..153, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__create_contract_from_init.snap b/crates/analyzer/tests/snapshots/analysis__create_contract_from_init.snap index b453480b04..df123b06f2 100644 --- a/crates/analyzer/tests/snapshots/analysis__create_contract_from_init.snap +++ b/crates/analyzer/tests/snapshots/analysis__create_contract_from_init.snap @@ -40,11 +40,14 @@ note: │ 13 │ ╭ pub fn get_foo_addr(self) -> address: 14 │ │ return self.foo_addr - │ ╰────────────────────────────^ attributes hash: 12485079837452748334 + │ ╰────────────────────────────^ attributes hash: 8904861176924811726 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 259..263, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__data_copying_stress.snap b/crates/analyzer/tests/snapshots/analysis__data_copying_stress.snap index be60c058f6..b739fa39f8 100644 --- a/crates/analyzer/tests/snapshots/analysis__data_copying_stress.snap +++ b/crates/analyzer/tests/snapshots/analysis__data_copying_stress.snap @@ -40,11 +40,14 @@ note: · │ 27 │ │ self.my_u256 = my_u256 28 │ │ self.my_other_u256 = my_other_u256 - │ ╰──────────────────────────────────────────^ attributes hash: 4258049002980316029 + │ ╰──────────────────────────────────────────^ attributes hash: 1971527150375113575 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 313..317, + }, ), ctx_decl: None, params: [ @@ -154,11 +157,14 @@ note: 30 │ ╭ pub fn set_to_my_other_vals(mut self): 31 │ │ self.my_string = self.my_other_string 32 │ │ self.my_u256 = self.my_other_u256 - │ ╰─────────────────────────────────────────^ attributes hash: 17189319825533802105 + │ ╰─────────────────────────────────────────^ attributes hash: 6287025791049792562 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 638..642, + }, ), ctx_decl: None, params: [], @@ -595,11 +601,14 @@ note: · │ 67 │ │ my_nums_mem = self.my_nums.to_mem() 68 │ │ return my_nums_mem - │ ╰──────────────────────────^ attributes hash: 14939519023271551283 + │ ╰──────────────────────────^ attributes hash: 1306567717312049 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1645..1649, + }, ), ctx_decl: None, params: [], @@ -742,11 +751,14 @@ note: 73 │ │ self.my_string.to_mem(), 74 │ │ self.my_u256.to_mem() 75 │ │ ) - │ ╰─────────^ attributes hash: 17228436346762880410 + │ ╰─────────^ attributes hash: 3465640054853167022 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1955..1959, + }, ), ctx_decl: Some( Mutable, @@ -927,11 +939,14 @@ note: │ 80 │ ╭ pub fn set_my_addrs(mut self, my_addrs: Array): 81 │ │ self.my_addrs = my_addrs - │ ╰────────────────────────────────^ attributes hash: 15240764995870306626 + │ ╰────────────────────────────────^ attributes hash: 6596479074654462354 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 2269..2273, + }, ), ctx_decl: None, params: [ @@ -975,11 +990,14 @@ note: │ 83 │ ╭ pub fn get_my_second_addr(self) -> address: 84 │ │ return self.my_addrs[1] - │ ╰───────────────────────────────^ attributes hash: 12485079837452748334 + │ ╰───────────────────────────────^ attributes hash: 11296848741241405402 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 2369..2373, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__erc20_token.snap b/crates/analyzer/tests/snapshots/analysis__erc20_token.snap index 05d7695324..100c71c6df 100644 --- a/crates/analyzer/tests/snapshots/analysis__erc20_token.snap +++ b/crates/analyzer/tests/snapshots/analysis__erc20_token.snap @@ -44,11 +44,14 @@ note: │ 27 │ ╭ pub fn name(self) -> String<100>: 28 │ │ return self._name.to_mem() - │ ╰──────────────────────────────────^ attributes hash: 10831185493383698657 + │ ╰──────────────────────────────────^ attributes hash: 10326840621732793325 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 681..685, + }, ), ctx_decl: None, params: [], @@ -84,11 +87,14 @@ note: │ 30 │ ╭ pub fn symbol(self) -> String<100>: 31 │ │ return self._symbol.to_mem() - │ ╰────────────────────────────────────^ attributes hash: 10831185493383698657 + │ ╰────────────────────────────────────^ attributes hash: 2821531269978251174 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 757..761, + }, ), ctx_decl: None, params: [], @@ -124,11 +130,14 @@ note: │ 33 │ ╭ pub fn decimals(self) -> u8: 34 │ │ return self._decimals - │ ╰─────────────────────────────^ attributes hash: 11796325298321211402 + │ ╰─────────────────────────────^ attributes hash: 15860653689999316634 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 837..841, + }, ), ctx_decl: None, params: [], @@ -158,11 +167,14 @@ note: │ 36 │ ╭ pub fn totalSupply(self) -> u256: 37 │ │ return self._total_supply - │ ╰─────────────────────────────────^ attributes hash: 9289100627868228400 + │ ╰─────────────────────────────────^ attributes hash: 6752201590413781727 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 904..908, + }, ), ctx_decl: None, params: [], @@ -192,11 +204,14 @@ note: │ 39 │ ╭ pub fn balanceOf(self, _ account: address) -> u256: 40 │ │ return self._balances[account] - │ ╰──────────────────────────────────────^ attributes hash: 6344387903326607307 + │ ╰──────────────────────────────────────^ attributes hash: 7037225850851392916 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 975..979, + }, ), ctx_decl: None, params: [ @@ -248,11 +263,14 @@ note: 42 │ ╭ pub fn transfer(mut self, ctx: Context, recipient: address, value: u256) -> bool: 43 │ │ self._transfer(ctx, sender: ctx.msg_sender(), recipient, value) 44 │ │ return true - │ ╰───────────────────^ attributes hash: 18175859635523729465 + │ ╰───────────────────^ attributes hash: 17848380029420472885 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1074..1078, + }, ), ctx_decl: Some( Mutable, @@ -332,11 +350,14 @@ note: │ 46 │ ╭ pub fn allowance(self, owner: address, spender: address) -> u256: 47 │ │ return self._allowances[owner][spender] - │ ╰───────────────────────────────────────────────^ attributes hash: 1367202090297541366 + │ ╰───────────────────────────────────────────────^ attributes hash: 5571416063430298361 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1250..1254, + }, ), ctx_decl: None, params: [ @@ -404,11 +425,14 @@ note: 49 │ ╭ pub fn approve(mut self, ctx: Context, spender: address, value: u256) -> bool: 50 │ │ self._approve(ctx, owner: ctx.msg_sender(), spender, value) 51 │ │ return true - │ ╰───────────────────^ attributes hash: 9370621096455052112 + │ ╰───────────────────^ attributes hash: 1010517131892538097 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1371..1375, + }, ), ctx_decl: Some( Mutable, @@ -491,11 +515,14 @@ note: 55 │ │ self._transfer(ctx, sender, recipient, value) 56 │ │ self._approve(ctx, owner: sender, spender: ctx.msg_sender(), value: self._allowances[sender][ctx.msg_sender()] - value) 57 │ │ return true - │ ╰───────────────────^ attributes hash: 1895583765156384920 + │ ╰───────────────────^ attributes hash: 7939067401153478982 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1548..1552, + }, ), ctx_decl: Some( Mutable, @@ -673,11 +700,14 @@ note: 59 │ ╭ pub fn increaseAllowance(mut self, ctx: Context, spender: address, addedValue: u256) -> bool: 60 │ │ self._approve(ctx, owner: ctx.msg_sender(), spender, value: self._allowances[ctx.msg_sender()][spender] + addedValue) 61 │ │ return true - │ ╰───────────────────^ attributes hash: 6150887204508679079 + │ ╰───────────────────^ attributes hash: 18429228409985716741 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 1930..1934, + }, ), ctx_decl: Some( Mutable, @@ -794,11 +824,14 @@ note: 63 │ ╭ pub fn decreaseAllowance(mut self, ctx: Context, spender: address, subtractedValue: u256) -> bool: 64 │ │ self._approve(ctx, owner: ctx.msg_sender(), spender, value: self._allowances[ctx.msg_sender()][spender] - subtractedValue) 65 │ │ return true - │ ╰───────────────────^ attributes hash: 15537926659857985492 + │ ╰───────────────────^ attributes hash: 6163388348340102461 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 2175..2179, + }, ), ctx_decl: Some( Mutable, @@ -919,11 +952,14 @@ note: 71 │ │ self._balances[sender] = self._balances[sender] - value 72 │ │ self._balances[recipient] = self._balances[recipient] + value 73 │ │ emit Transfer(ctx, from: sender, to: recipient, value) - │ ╰──────────────────────────────────────────────────────────────^ attributes hash: 12890522393118880186 + │ ╰──────────────────────────────────────────────────────────────^ attributes hash: 10498598608658691613 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 2418..2422, + }, ), ctx_decl: Some( Mutable, @@ -1165,11 +1201,14 @@ note: 78 │ │ self._total_supply = self._total_supply + value 79 │ │ self._balances[account] = self._balances[account] + value 80 │ │ emit Transfer(ctx, from: address(0), to: account, value) - │ ╰────────────────────────────────────────────────────────────────^ attributes hash: 7089552335989807804 + │ ╰────────────────────────────────────────────────────────────────^ attributes hash: 14466326291355393221 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 2846..2850, + }, ), ctx_decl: Some( Mutable, @@ -1382,11 +1421,14 @@ note: 85 │ │ self._balances[account] = self._balances[account] - value 86 │ │ self._total_supply = self._total_supply - value 87 │ │ emit Transfer(ctx, from: account, to: address(0), value) - │ ╰────────────────────────────────────────────────────────────────^ attributes hash: 7089552335989807804 + │ ╰────────────────────────────────────────────────────────────────^ attributes hash: 4943182168588040219 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 3209..3213, + }, ), ctx_decl: Some( Mutable, @@ -1599,11 +1641,14 @@ note: 91 │ │ assert spender != address(0) 92 │ │ self._allowances[owner][spender] = value 93 │ │ emit Approval(ctx, owner, spender, value) - │ ╰─────────────────────────────────────────────────^ attributes hash: 3891800734257590100 + │ ╰─────────────────────────────────────────────────^ attributes hash: 11548731968227902483 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 3575..3579, + }, ), ctx_decl: Some( Mutable, @@ -1776,11 +1821,14 @@ note: │ 95 │ ╭ fn _setup_decimals(mut self, _ decimals_: u8): 96 │ │ self._decimals = decimals_ - │ ╰──────────────────────────────────^ attributes hash: 14520659671635291265 + │ ╰──────────────────────────────────^ attributes hash: 7541839769003135213 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 3842..3846, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__guest_book.snap b/crates/analyzer/tests/snapshots/analysis__guest_book.snap index 175f5c73ac..d641c6ff36 100644 --- a/crates/analyzer/tests/snapshots/analysis__guest_book.snap +++ b/crates/analyzer/tests/snapshots/analysis__guest_book.snap @@ -24,11 +24,14 @@ note: 16 │ │ 17 │ │ # Emit the `Signed` event 18 │ │ emit Signed(ctx, book_msg) - │ ╰──────────────────────────────────^ attributes hash: 3588090493742034077 + │ ╰──────────────────────────────────^ attributes hash: 10126475880915437347 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 353..357, + }, ), ctx_decl: Some( Mutable, @@ -130,11 +133,14 @@ note: 21 │ │ # Copying data from storage to memory 22 │ │ # has to be done explicitly via `to_mem()` 23 │ │ return self.messages[addr].to_mem() - │ ╰───────────────────────────────────────────^ attributes hash: 14819399205100473448 + │ ╰───────────────────────────────────────────^ attributes hash: 8213707984659401459 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 603..607, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__nested_map.snap b/crates/analyzer/tests/snapshots/analysis__nested_map.snap index 5a5617cd76..51af268456 100644 --- a/crates/analyzer/tests/snapshots/analysis__nested_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__nested_map.snap @@ -16,11 +16,14 @@ note: │ 5 │ ╭ pub fn read_bar(self, a: address, b: address) -> u256: 6 │ │ return self.bar[a][b] - │ ╰─────────────────────────────^ attributes hash: 554384316729923119 + │ ╰─────────────────────────────^ attributes hash: 11934952384227095071 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 116..120, + }, ), ctx_decl: None, params: [ @@ -87,11 +90,14 @@ note: │ 8 │ ╭ pub fn write_bar(mut self, a: address, b: address, value: u256): 9 │ │ self.bar[a][b] = value - │ ╰──────────────────────────────^ attributes hash: 18098070794348656247 + │ ╰──────────────────────────────^ attributes hash: 15803849334142506353 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 211..215, + }, ), ctx_decl: None, params: [ @@ -170,11 +176,14 @@ note: │ 11 │ ╭ pub fn read_baz(self, a: address, b: u256) -> bool: 12 │ │ return self.baz[a][b] - │ ╰─────────────────────────────^ attributes hash: 11496121246963142057 + │ ╰─────────────────────────────^ attributes hash: 9743077837848366854 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 307..311, + }, ), ctx_decl: None, params: [ @@ -241,11 +250,14 @@ note: │ 14 │ ╭ pub fn write_baz(mut self, a: address, b: u256, value: bool): 15 │ │ self.baz[a][b] = value - │ ╰──────────────────────────────^ attributes hash: 4861087177030475677 + │ ╰──────────────────────────────^ attributes hash: 7987751783380438642 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 399..403, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__ownable.snap b/crates/analyzer/tests/snapshots/analysis__ownable.snap index ba9a230a11..ea713a2d02 100644 --- a/crates/analyzer/tests/snapshots/analysis__ownable.snap +++ b/crates/analyzer/tests/snapshots/analysis__ownable.snap @@ -22,11 +22,14 @@ note: │ 13 │ ╭ pub fn owner(self) -> address: 14 │ │ return self._owner - │ ╰──────────────────────^ attributes hash: 12485079837452748334 + │ ╰──────────────────────^ attributes hash: 6972949257956365152 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 246..250, + }, ), ctx_decl: None, params: [], @@ -56,11 +59,14 @@ note: 17 │ │ assert ctx.msg_sender() == self._owner 18 │ │ self._owner = address(0) 19 │ │ emit OwnershipTransferred(ctx, previousOwner: ctx.msg_sender(), newOwner: address(0)) - │ ╰─────────────────────────────────────────────────────────────────────────────────────────^ attributes hash: 16312728857174474058 + │ ╰─────────────────────────────────────────────────────────────────────────────────────────^ attributes hash: 15898452962760116643 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 319..323, + }, ), ctx_decl: Some( Mutable, @@ -185,11 +191,14 @@ note: 23 │ │ assert newOwner != address(0) 24 │ │ self._owner = newOwner 25 │ │ emit OwnershipTransferred(ctx, previousOwner: ctx.msg_sender(), newOwner) - │ ╰─────────────────────────────────────────────────────────────────────────────^ attributes hash: 4011659347690782027 + │ ╰─────────────────────────────────────────────────────────────────────────────^ attributes hash: 14397139561406753900 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 534..538, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/analysis__pure_fn_standalone.snap b/crates/analyzer/tests/snapshots/analysis__pure_fn_standalone.snap index 14ea0a7a2a..ee6f3cc50f 100644 --- a/crates/analyzer/tests/snapshots/analysis__pure_fn_standalone.snap +++ b/crates/analyzer/tests/snapshots/analysis__pure_fn_standalone.snap @@ -68,11 +68,14 @@ note: 11 │ │ self.points[user] += add_bonus(val) 12 │ │ else: 13 │ │ self.points[user] += val - │ ╰────────────────────────────────────^ attributes hash: 16233081623641993418 + │ ╰────────────────────────────────────^ attributes hash: 1176437349362264900 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 156..160, + }, ), ctx_decl: None, params: [ @@ -182,11 +185,14 @@ note: 18 │ │ self.cool_users[a] = true 19 │ │ self.add_points(a, 100) 20 │ │ return self.points[a] - │ ╰─────────────────────────────^ attributes hash: 12461661329008412434 + │ ╰─────────────────────────────^ attributes hash: 4147334020350999546 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 346..350, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn.snap b/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn.snap index ed21860ab5..c40908bbae 100644 --- a/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn.snap +++ b/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn.snap @@ -8,11 +8,14 @@ note: │ 4 │ ╭ pub fn bar(self) -> u256: 5 │ │ return foo() - │ ╰────────────────────^ attributes hash: 9289100627868228400 + │ ╰────────────────────^ attributes hash: 143425425812623756 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 114..118, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn_with_args.snap b/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn_with_args.snap index 6890569b91..179c33ed7d 100644 --- a/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn_with_args.snap +++ b/crates/analyzer/tests/snapshots/analysis__return_u256_from_called_fn_with_args.snap @@ -170,11 +170,14 @@ note: 9 │ ╭ pub fn bar(mut self) -> u256: 10 │ │ self.baz[0] = 43 11 │ │ return foo(5, 2, cem(), 25 + 25, self.baz[0]) - │ ╰─────────────────────────────────────────────────────^ attributes hash: 14378415039933113528 + │ ╰─────────────────────────────────────────────────────^ attributes hash: 1177483248959741855 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 227..231, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__revert.snap b/crates/analyzer/tests/snapshots/analysis__revert.snap index 3b0358d6d7..4f42e680f5 100644 --- a/crates/analyzer/tests/snapshots/analysis__revert.snap +++ b/crates/analyzer/tests/snapshots/analysis__revert.snap @@ -131,11 +131,14 @@ note: 19 │ ╭ pub fn revert_other_error_from_sto(mut self): 20 │ │ self.my_other_error = OtherError(msg: 1, val: true) 21 │ │ revert self.my_other_error.to_mem() - │ ╰───────────────────────────────────────────^ attributes hash: 17189319825533802105 + │ ╰───────────────────────────────────────────^ attributes hash: 13800925827926653181 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 389..393, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__sized_vals_in_sto.snap b/crates/analyzer/tests/snapshots/analysis__sized_vals_in_sto.snap index 5cf9615e96..6c82c822ab 100644 --- a/crates/analyzer/tests/snapshots/analysis__sized_vals_in_sto.snap +++ b/crates/analyzer/tests/snapshots/analysis__sized_vals_in_sto.snap @@ -28,11 +28,14 @@ note: │ 13 │ ╭ pub fn write_num(mut self, x: u256): 14 │ │ self.num = x - │ ╰────────────────────^ attributes hash: 8635218000678440620 + │ ╰────────────────────^ attributes hash: 13211597784218302342 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 219..223, + }, ), ctx_decl: None, params: [ @@ -75,11 +78,14 @@ note: │ 16 │ ╭ pub fn read_num(self) -> u256: 17 │ │ return self.num - │ ╰───────────────────────^ attributes hash: 9289100627868228400 + │ ╰───────────────────────^ attributes hash: 343355851351924054 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 277..281, + }, ), ctx_decl: None, params: [], @@ -109,11 +115,14 @@ note: │ 19 │ ╭ pub fn write_nums(mut self, x: Array): 20 │ │ self.nums = x - │ ╰─────────────────────^ attributes hash: 7327163685010241593 + │ ╰─────────────────────^ attributes hash: 9734796568044748023 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 343..347, + }, ), ctx_decl: None, params: [ @@ -159,11 +168,14 @@ note: │ 22 │ ╭ pub fn read_nums(self) -> Array: 23 │ │ return self.nums.to_mem() - │ ╰─────────────────────────────────^ attributes hash: 15337708133982484829 + │ ╰─────────────────────────────────^ attributes hash: 7976753079684333422 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 414..418, + }, ), ctx_decl: None, params: [], @@ -202,11 +214,14 @@ note: │ 25 │ ╭ pub fn write_str(mut self, x: String<26>): 26 │ │ self.str = x - │ ╰────────────────────^ attributes hash: 14702972272118302413 + │ ╰────────────────────^ attributes hash: 10576260109919667904 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 500..504, + }, ), ctx_decl: None, params: [ @@ -249,11 +264,14 @@ note: │ 28 │ ╭ pub fn read_str(self) -> String<26>: 29 │ │ return self.str.to_mem() - │ ╰────────────────────────────────^ attributes hash: 18293893723021688630 + │ ╰────────────────────────────────^ attributes hash: 11311838496933613771 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 564..568, + }, ), ctx_decl: None, params: [], @@ -294,11 +312,14 @@ note: 35 │ │ nums: self.nums.to_mem(), 36 │ │ str: self.str.to_mem() 37 │ │ ) - │ ╰─────────^ attributes hash: 17228436346762880410 + │ ╰─────────^ attributes hash: 10599346875189913769 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 641..645, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/analysis__struct_fns.snap b/crates/analyzer/tests/snapshots/analysis__struct_fns.snap index 0c9063b5c4..ad578577ec 100644 --- a/crates/analyzer/tests/snapshots/analysis__struct_fns.snap +++ b/crates/analyzer/tests/snapshots/analysis__struct_fns.snap @@ -111,11 +111,14 @@ note: │ 12 │ ╭ pub fn x(self) -> u64: 13 │ │ return self.x - │ ╰─────────────────^ attributes hash: 3845322726740023706 + │ ╰─────────────────^ attributes hash: 4167408499625905778 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 212..216, + }, ), ctx_decl: None, params: [], @@ -147,11 +150,14 @@ note: 16 │ │ let old: u64 = self.x 17 │ │ self.x = x 18 │ │ return old - │ ╰──────────────^ attributes hash: 4497302278450658077 + │ ╰──────────────^ attributes hash: 6114760768441898057 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 264..268, + }, ), ctx_decl: None, params: [ @@ -218,11 +224,14 @@ note: 23 │ │ # self.x = self.y panics. see issue #590 24 │ │ self.x = y 25 │ │ self.y = x - │ ╰──────────────^ attributes hash: 17189319825533802105 + │ ╰──────────────^ attributes hash: 13090218261873211462 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 366..370, + }, ), ctx_decl: None, params: [], @@ -288,11 +297,14 @@ note: 27 │ ╭ pub fn translate(mut self, x: u64, y: u64): 28 │ │ self.x += x 29 │ │ self.y += y - │ ╰───────────────^ attributes hash: 7376192337270331964 + │ ╰───────────────^ attributes hash: 9221797471724589001 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 520..524, + }, ), ctx_decl: None, params: [ @@ -359,11 +371,14 @@ note: 32 │ │ let x: u64 = self.x + other.x 33 │ │ let y: u64 = self.y + other.y 34 │ │ return Point(x, y) - │ ╰──────────────────────^ attributes hash: 2247769738096863780 + │ ╰──────────────────────^ attributes hash: 5701644196168333822 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 589..593, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__structs.snap b/crates/analyzer/tests/snapshots/analysis__structs.snap index 26f50ae3a1..cf8ac8ca8d 100644 --- a/crates/analyzer/tests/snapshots/analysis__structs.snap +++ b/crates/analyzer/tests/snapshots/analysis__structs.snap @@ -96,11 +96,14 @@ note: │ 24 │ ╭ pub fn encode(self) -> Array: 25 │ │ return self.abi_encode() - │ ╰────────────────────────────────^ attributes hash: 14742148898514624211 + │ ╰────────────────────────────────^ attributes hash: 18020747797794292579 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 407..411, + }, ), ctx_decl: None, params: [], @@ -133,11 +136,14 @@ note: │ 27 │ ╭ pub fn hash(self) -> u256: 28 │ │ return keccak256(self.encode()) - │ ╰───────────────────────────────────────^ attributes hash: 9289100627868228400 + │ ╰───────────────────────────────────────^ attributes hash: 17776866623336655671 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 482..486, + }, ), ctx_decl: None, params: [], @@ -173,11 +179,14 @@ note: │ 30 │ ╭ pub fn price_per_sqft(self) -> u256: 31 │ │ return self.price / self.size - │ ╰─────────────────────────────────────^ attributes hash: 9289100627868228400 + │ ╰─────────────────────────────────────^ attributes hash: 6629708603794113030 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 564..568, + }, ), ctx_decl: None, params: [], @@ -222,11 +231,14 @@ note: 33 │ ╭ pub fn expand(mut self): 34 │ │ self.rooms += 1 35 │ │ self.size += 100 - │ ╰────────────────────────^ attributes hash: 17189319825533802105 + │ ╰────────────────────────^ attributes hash: 9812201815424359002 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 640..644, + }, ), ctx_decl: None, params: [], @@ -279,11 +291,14 @@ note: · │ 86 │ │ 87 │ │ return self.my_bar.name.to_mem() - │ ╰────────────────────────────────────────^ attributes hash: 9253815641596727115 + │ ╰────────────────────────────────────────^ attributes hash: 1803424691938407914 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 789..793, + }, ), ctx_decl: None, params: [], @@ -1093,11 +1108,14 @@ note: · │ 134 │ │ 135 │ │ return val.name - │ ╰───────────────────────^ attributes hash: 10553685725301955303 + │ ╰───────────────────────^ attributes hash: 16946039741182464336 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 2522..2526, + }, ), ctx_decl: None, params: [], @@ -1727,11 +1745,14 @@ note: 137 │ ╭ pub fn create_mixed(self) -> u256: 138 │ │ let mixed: Mixed = Mixed.new(1) 139 │ │ return mixed.foo - │ ╰────────────────────────^ attributes hash: 9289100627868228400 + │ ╰────────────────────────^ attributes hash: 15719621379267994165 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 4015..4019, + }, ), ctx_decl: None, params: [], @@ -1775,11 +1796,14 @@ note: │ 141 │ ╭ pub fn set_house(mut self, data: House): 142 │ │ self.my_house = data - │ ╰────────────────────────────^ attributes hash: 13579765403560590701 + │ ╰────────────────────────────^ attributes hash: 16291808881491050034 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 4121..4125, + }, ), ctx_decl: None, params: [ @@ -1823,11 +1847,14 @@ note: │ 144 │ ╭ pub fn get_house(self) -> House: 145 │ │ return self.my_house.to_mem() - │ ╰─────────────────────────────────────^ attributes hash: 6094909767762441039 + │ ╰─────────────────────────────────────^ attributes hash: 4945489027941496916 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 4192..4196, + }, ), ctx_decl: None, params: [], @@ -1869,11 +1896,14 @@ note: · │ 178 │ │ assert self.my_house.rooms == u8(100) 179 │ │ assert self.my_house.vacant - │ ╰───────────────────────────────────^ attributes hash: 17189319825533802105 + │ ╰───────────────────────────────────^ attributes hash: 4380936255212012039 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 4275..4279, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__tuple_stress.snap b/crates/analyzer/tests/snapshots/analysis__tuple_stress.snap index c72b1ff937..099eaedb32 100644 --- a/crates/analyzer/tests/snapshots/analysis__tuple_stress.snap +++ b/crates/analyzer/tests/snapshots/analysis__tuple_stress.snap @@ -470,11 +470,14 @@ note: 31 │ ╭ pub fn set_my_sto_tuple(mut self, my_u256: u256, my_i32: i32): 32 │ │ assert self.my_sto_tuple.item0 == u256(0) and self.my_sto_tuple.item1 == i32(0) 33 │ │ self.my_sto_tuple = (my_u256, my_i32) - │ ╰─────────────────────────────────────────────^ attributes hash: 4443582922230575685 + │ ╰─────────────────────────────────────────────^ attributes hash: 9638530552934349387 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 924..928, + }, ), ctx_decl: None, params: [ @@ -598,11 +601,14 @@ note: │ 35 │ ╭ pub fn get_my_sto_tuple(self) -> (u256, i32): 36 │ │ return self.my_sto_tuple.to_mem() - │ ╰─────────────────────────────────────────^ attributes hash: 17013523245314192169 + │ ╰─────────────────────────────────────────^ attributes hash: 16151200552390194455 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1122..1126, + }, ), ctx_decl: None, params: [], @@ -654,11 +660,14 @@ note: · │ 44 │ │ ) 45 │ │ emit_my_event(ctx, my_tuple) - │ ╰────────────────────────────────────^ attributes hash: 17228436346762880410 + │ ╰────────────────────────────────────^ attributes hash: 16910797897652616193 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1219..1223, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/analysis__two_contracts.snap b/crates/analyzer/tests/snapshots/analysis__two_contracts.snap index 6fa0a1ce9e..f7a72b8ea5 100644 --- a/crates/analyzer/tests/snapshots/analysis__two_contracts.snap +++ b/crates/analyzer/tests/snapshots/analysis__two_contracts.snap @@ -15,11 +15,14 @@ note: 9 │ ╭ pub fn foo(self, ctx: Context) -> u256: 10 │ │ self.other.set_foo_addr(ctx.self_address()) 11 │ │ return self.other.answer() - │ ╰──────────────────────────────────^ attributes hash: 9380543137829531562 + │ ╰──────────────────────────────────^ attributes hash: 4490409360832373972 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 158..162, + }, ), ctx_decl: Some( Mutable, @@ -160,13 +163,16 @@ note: note: ┌─ two_contracts.fe:19:5 │ -19 │ ╭ pub fn set_foo_addr(self, ctx: Context, _ addr: address): +19 │ ╭ pub fn set_foo_addr(mut self, ctx: Context, _ addr: address): 20 │ │ self.other = Foo(ctx, addr) - │ ╰───────────────────────────────────^ attributes hash: 9324698752842718706 + │ ╰───────────────────────────────────^ attributes hash: 7772662931551478644 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 401..405, + }, ), ctx_decl: Some( Mutable, @@ -231,11 +237,14 @@ note: │ 22 │ ╭ pub fn answer(self) -> u256: 23 │ │ return self.other.add(20, 22) - │ ╰─────────────────────────────────────^ attributes hash: 9289100627868228400 + │ ╰─────────────────────────────────────^ attributes hash: 11070438767694404534 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 494..498, + }, ), ctx_decl: None, params: [], diff --git a/crates/analyzer/tests/snapshots/analysis__type_aliases.snap b/crates/analyzer/tests/snapshots/analysis__type_aliases.snap index 07d0b17ab8..2729b2f786 100644 --- a/crates/analyzer/tests/snapshots/analysis__type_aliases.snap +++ b/crates/analyzer/tests/snapshots/analysis__type_aliases.snap @@ -58,17 +58,20 @@ note: note: ┌─ type_aliases.fe:17:5 │ -17 │ ╭ pub fn post(self, ctx: Context, body: PostBody): +17 │ ╭ pub fn post(mut self, ctx: Context, body: PostBody): 18 │ │ # id: PostId = keccak256(body.abi_encode()) 19 │ │ let id: PostId = 0 20 │ │ self.posts[id] = body 21 │ │ self.authors[ctx.msg_sender()] 22 │ │ self.scoreboard[id] = 0 - │ ╰───────────────────────────────^ attributes hash: 14250234635461040841 + │ ╰───────────────────────────────^ attributes hash: 6463244129054231356 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 331..335, + }, ), ctx_decl: Some( Mutable, @@ -180,15 +183,18 @@ note: note: ┌─ type_aliases.fe:24:5 │ -24 │ ╭ pub fn upvote(self, id: PostId) -> Score: +24 │ ╭ pub fn upvote(mut self, id: PostId) -> Score: 25 │ │ let score: Score = self.scoreboard[id] + 1 26 │ │ self.scoreboard[id] = score 27 │ │ return score - │ ╰────────────────────^ attributes hash: 14123054955261014132 + │ ╰────────────────────^ attributes hash: 4755174337893161025 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 571..575, + }, ), ctx_decl: None, params: [ @@ -273,11 +279,14 @@ note: │ 29 │ ╭ pub fn get_post(self, id: PostId) -> PostBody: 30 │ │ return self.posts[id].to_mem() - │ ╰──────────────────────────────────────^ attributes hash: 10995294168466626598 + │ ╰──────────────────────────────────────^ attributes hash: 3813415160436882779 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 728..732, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u128_u128_map.snap b/crates/analyzer/tests/snapshots/analysis__u128_u128_map.snap index d7759a904c..488d347fd6 100644 --- a/crates/analyzer/tests/snapshots/analysis__u128_u128_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u128_u128_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u128) -> u128: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 426410825149342032 + │ ╰────────────────────────────^ attributes hash: 404178019243934124 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 60..64, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u128, value: u128): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 6200873427451299090 + │ ╰─────────────────────────────^ attributes hash: 16092072226699986412 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 141..145, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u16_u16_map.snap b/crates/analyzer/tests/snapshots/analysis__u16_u16_map.snap index 89155f211a..6b15530745 100644 --- a/crates/analyzer/tests/snapshots/analysis__u16_u16_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u16_u16_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u16) -> u16: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 7970851140763241154 + │ ╰────────────────────────────^ attributes hash: 11163739175449560362 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 58..62, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u16, value: u16): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 8665346967448469066 + │ ╰─────────────────────────────^ attributes hash: 974911175125490270 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 137..141, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u256_u256_map.snap b/crates/analyzer/tests/snapshots/analysis__u256_u256_map.snap index d0647783a7..450aa4f8d1 100644 --- a/crates/analyzer/tests/snapshots/analysis__u256_u256_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u256_u256_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u256) -> u256: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 2266959658310540009 + │ ╰────────────────────────────^ attributes hash: 560845592606279886 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 60..64, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u256, value: u256): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 17041393498318565502 + │ ╰─────────────────────────────^ attributes hash: 441920125614237371 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 141..145, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u32_u32_map.snap b/crates/analyzer/tests/snapshots/analysis__u32_u32_map.snap index 9fa39c2914..732504ee14 100644 --- a/crates/analyzer/tests/snapshots/analysis__u32_u32_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u32_u32_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u32) -> u32: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 12098804831101653503 + │ ╰────────────────────────────^ attributes hash: 6642787142700032627 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 58..62, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u32, value: u32): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 3334516666503128091 + │ ╰─────────────────────────────^ attributes hash: 17906619701827173974 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 137..141, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u64_u64_map.snap b/crates/analyzer/tests/snapshots/analysis__u64_u64_map.snap index e1be84ee93..51330ee590 100644 --- a/crates/analyzer/tests/snapshots/analysis__u64_u64_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u64_u64_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u64) -> u64: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 12842147379290415356 + │ ╰────────────────────────────^ attributes hash: 17594672210509140896 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 58..62, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u64, value: u64): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 13743965502752577725 + │ ╰─────────────────────────────^ attributes hash: 5792141704406555037 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 137..141, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__u8_u8_map.snap b/crates/analyzer/tests/snapshots/analysis__u8_u8_map.snap index dbed6b72b5..b6da68017b 100644 --- a/crates/analyzer/tests/snapshots/analysis__u8_u8_map.snap +++ b/crates/analyzer/tests/snapshots/analysis__u8_u8_map.snap @@ -14,11 +14,14 @@ note: │ 4 │ ╭ pub fn read_bar(self, key: u8) -> u8: 5 │ │ return self.bar[key] - │ ╰────────────────────────────^ attributes hash: 15562933306564534468 + │ ╰────────────────────────────^ attributes hash: 6428918794644454532 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 56..60, + }, ), ctx_decl: None, params: [ @@ -69,11 +72,14 @@ note: │ 7 │ ╭ pub fn write_bar(mut self, key: u8, value: u8): 8 │ │ self.bar[key] = value - │ ╰─────────────────────────────^ attributes hash: 5252929252150173272 + │ ╰─────────────────────────────^ attributes hash: 8801421488558033799 │ = FunctionSignature { self_decl: Some( - MutRef, + SelfDecl { + kind: MutRef, + span: 133..137, + }, ), ctx_decl: None, params: [ diff --git a/crates/analyzer/tests/snapshots/analysis__uniswap.snap b/crates/analyzer/tests/snapshots/analysis__uniswap.snap index 4f3aaddbe3..e75ee444bb 100644 --- a/crates/analyzer/tests/snapshots/analysis__uniswap.snap +++ b/crates/analyzer/tests/snapshots/analysis__uniswap.snap @@ -196,11 +196,14 @@ note: │ 68 │ ╭ pub fn factory(self) -> address: 69 │ │ return self.factory - │ ╰───────────────────────────^ attributes hash: 12485079837452748334 + │ ╰───────────────────────────^ attributes hash: 3883682654554824383 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1412..1416, + }, ), ctx_decl: None, params: [], @@ -228,11 +231,14 @@ note: │ 71 │ ╭ pub fn token0(self) -> address: 72 │ │ return self.token0 - │ ╰──────────────────────────^ attributes hash: 12485079837452748334 + │ ╰──────────────────────────^ attributes hash: 12453447202682215801 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1477..1481, + }, ), ctx_decl: None, params: [], @@ -260,11 +266,14 @@ note: │ 74 │ ╭ pub fn token1(self) -> address: 75 │ │ return self.token1 - │ ╰──────────────────────────^ attributes hash: 12485079837452748334 + │ ╰──────────────────────────^ attributes hash: 609876714974830132 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 1541..1545, + }, ), ctx_decl: None, params: [], @@ -290,15 +299,18 @@ note: note: ┌─ uniswap.fe:77:5 │ -77 │ ╭ fn _mint(self, ctx: Context, to: address, value: u256): +77 │ ╭ fn _mint(mut self, ctx: Context, to: address, value: u256): 78 │ │ self.total_supply = self.total_supply + value 79 │ │ self.balances[to] = self.balances[to] + value 80 │ │ emit Transfer(ctx, from: address(0), to, value) - │ ╰───────────────────────────────────────────────────────^ attributes hash: 9234088867140573589 + │ ╰───────────────────────────────────────────────────────^ attributes hash: 2838731223825333376 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 1604..1608, + }, ), ctx_decl: Some( Mutable, @@ -472,15 +484,18 @@ note: note: ┌─ uniswap.fe:82:5 │ -82 │ ╭ fn _burn(self, ctx: Context, from: address, value: u256): +82 │ ╭ fn _burn(mut self, ctx: Context, from: address, value: u256): 83 │ │ self.balances[from] = self.balances[from] - value 84 │ │ self.total_supply = self.total_supply - value 85 │ │ emit Transfer(ctx, from, to: address(0), value) - │ ╰───────────────────────────────────────────────────────^ attributes hash: 297600118512843906 + │ ╰───────────────────────────────────────────────────────^ attributes hash: 4093973936631334187 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 1833..1837, + }, ), ctx_decl: Some( Mutable, @@ -654,14 +669,17 @@ note: note: ┌─ uniswap.fe:88:5 │ -88 │ ╭ fn _approve(self, ctx: Context, owner: address, spender: address, value: u256): +88 │ ╭ fn _approve(mut self, ctx: Context, owner: address, spender: address, value: u256): 89 │ │ self.allowances[owner][spender] = value 90 │ │ emit Approval(ctx, owner, spender, value) - │ ╰─────────────────────────────────────────────────^ attributes hash: 11597788745459791135 + │ ╰─────────────────────────────────────────────────^ attributes hash: 15735622105416244689 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 2072..2076, + }, ), ctx_decl: Some( Mutable, @@ -800,15 +818,18 @@ note: note: ┌─ uniswap.fe:93:5 │ -93 │ ╭ fn _transfer(self, ctx: Context, from: address, to: address, value: u256): +93 │ ╭ fn _transfer(mut self, ctx: Context, from: address, to: address, value: u256): 94 │ │ self.balances[from] = self.balances[from] - value 95 │ │ self.balances[to] = self.balances[to] + value 96 │ │ emit Transfer(ctx, from, to, value) - │ ╰───────────────────────────────────────────^ attributes hash: 15760097961245082121 + │ ╰───────────────────────────────────────────^ attributes hash: 12485952734392732060 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 2261..2265, + }, ), ctx_decl: Some( Mutable, @@ -1001,14 +1022,17 @@ note: note: ┌─ uniswap.fe:98:5 │ - 98 │ ╭ pub fn approve(self, ctx: Context, spender: address, value: u256) -> bool: + 98 │ ╭ pub fn approve(mut self, ctx: Context, spender: address, value: u256) -> bool: 99 │ │ self._approve(ctx, owner: ctx.msg_sender(), spender, value) 100 │ │ return true - │ ╰───────────────────^ attributes hash: 12567526558914937321 + │ ╰───────────────────^ attributes hash: 15682368485749544822 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 2503..2507, + }, ), ctx_decl: Some( Mutable, @@ -1086,14 +1110,17 @@ note: note: ┌─ uniswap.fe:102:5 │ -102 │ ╭ pub fn transfer(self, ctx: Context, to: address, value: u256) -> bool: +102 │ ╭ pub fn transfer(mut self, ctx: Context, to: address, value: u256) -> bool: 103 │ │ self._transfer(ctx, from: ctx.msg_sender(), to, value) 104 │ │ return true - │ ╰───────────────────^ attributes hash: 5261963710934032634 + │ ╰───────────────────^ attributes hash: 1505213770801861479 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 2676..2680, + }, ), ctx_decl: Some( Mutable, @@ -1171,16 +1198,19 @@ note: note: ┌─ uniswap.fe:106:5 │ -106 │ ╭ pub fn transferFrom(self, ctx: Context, from: address, to: address, value: u256) -> bool: +106 │ ╭ pub fn transferFrom(mut self, ctx: Context, from: address, to: address, value: u256) -> bool: 107 │ │ assert self.allowances[from][ctx.msg_sender()] >= value 108 │ │ self.allowances[from][ctx.msg_sender()] = self.allowances[from][ctx.msg_sender()] - value 109 │ │ self._transfer(ctx, from, to, value) 110 │ │ return true - │ ╰───────────────────^ attributes hash: 8912904674606830358 + │ ╰───────────────────^ attributes hash: 15014414441315333161 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 2843..2847, + }, ), ctx_decl: Some( Mutable, @@ -1369,11 +1399,14 @@ note: │ 112 │ ╭ pub fn balanceOf(self, _ account: address) -> u256: 113 │ │ return self.balances[account] - │ ╰─────────────────────────────────────^ attributes hash: 6344387903326607307 + │ ╰─────────────────────────────────────^ attributes hash: 14778835780928648959 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 3162..3166, + }, ), ctx_decl: None, params: [ @@ -1424,11 +1457,14 @@ note: │ 115 │ ╭ pub fn get_reserves(self) -> (u256, u256, u256): 116 │ │ return (self.reserve0, self.reserve1, self.block_timestamp_last) - │ ╰────────────────────────────────────────────────────────────────────────^ attributes hash: 1210821935383321449 + │ ╰────────────────────────────────────────────────────────────────────────^ attributes hash: 8579517199767811469 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 3260..3264, + }, ), ctx_decl: None, params: [], @@ -1494,15 +1530,18 @@ note: note: ┌─ uniswap.fe:119:5 │ -119 │ ╭ pub fn initialize(self, ctx: Context, token0: address, token1: address): +119 │ ╭ pub fn initialize(mut self, ctx: Context, token0: address, token1: address): 120 │ │ assert ctx.msg_sender() == self.factory, "UniswapV2: FORBIDDEN" 121 │ │ self.token0 = token0 122 │ │ self.token1 = token1 - │ ╰────────────────────────────^ attributes hash: 9513029055875624394 + │ ╰────────────────────────────^ attributes hash: 1457888239674380142 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 3444..3448, + }, ), ctx_decl: Some( Mutable, @@ -1600,18 +1639,21 @@ note: note: ┌─ uniswap.fe:125:5 │ -125 │ ╭ fn _update(self, ctx: Context, balance0: u256, balance1: u256, reserve0: u256, reserve1: u256): +125 │ ╭ fn _update(mut self, ctx: Context, balance0: u256, balance1: u256, reserve0: u256, reserve1: u256): 126 │ │ # changed from u32s 127 │ │ let block_timestamp: u256 = ctx.block_timestamp() % 2**32 128 │ │ # TODO: reproduce desired overflow (https://github.com/ethereum/fe/issues/286) · │ 137 │ │ self.block_timestamp_last = block_timestamp 138 │ │ emit Sync(ctx, reserve0: self.reserve0, reserve1: self.reserve1) - │ ╰────────────────────────────────────────────────────────────────────────^ attributes hash: 10294992167718490743 + │ ╰────────────────────────────────────────────────────────────────────────^ attributes hash: 1767704501231443649 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 3724..3728, + }, ), ctx_decl: Some( Mutable, @@ -1944,18 +1986,21 @@ note: note: ┌─ uniswap.fe:141:5 │ -141 │ ╭ fn _mint_fee(self, ctx: Context, reserve0: u256, reserve1: u256) -> bool: +141 │ ╭ fn _mint_fee(mut self, ctx: Context, reserve0: u256, reserve1: u256) -> bool: 142 │ │ let fee_to: address = UniswapV2Factory(ctx, self.factory).fee_to() 143 │ │ let fee_on: bool = fee_to != address(0) 144 │ │ let k_last: u256 = self.k_last # gas savings · │ 157 │ │ 158 │ │ return fee_on - │ ╰─────────────────────^ attributes hash: 16616467919368541512 + │ ╰─────────────────────^ attributes hash: 5237904610411090364 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 4727..4731, + }, ), ctx_decl: Some( Mutable, @@ -2224,18 +2269,21 @@ note: note: ┌─ uniswap.fe:161:5 │ -161 │ ╭ pub fn mint(self, ctx: Context, to: address) -> u256: +161 │ ╭ pub fn mint(mut self, ctx: Context, to: address) -> u256: 162 │ │ let MINIMUM_LIQUIDITY: u256 = 1000 163 │ │ let reserve0: u256 = self.reserve0 164 │ │ let reserve1: u256 = self.reserve1 · │ 187 │ │ emit Mint(ctx, sender: ctx.msg_sender(), amount0, amount1) 188 │ │ return liquidity - │ ╰────────────────────────^ attributes hash: 1471928386700229908 + │ ╰────────────────────────^ attributes hash: 4920140949246745606 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 5692..5696, + }, ), ctx_decl: Some( Mutable, @@ -2655,18 +2703,21 @@ note: note: ┌─ uniswap.fe:191:5 │ -191 │ ╭ pub fn burn(self, ctx: Context, to: address) -> (u256, u256): +191 │ ╭ pub fn burn(mut self, ctx: Context, to: address) -> (u256, u256): 192 │ │ let reserve0: u256 = self.reserve0 193 │ │ let reserve1: u256 = self.reserve1 194 │ │ let token0: ERC20 = ERC20(ctx, self.token0) · │ 216 │ │ emit Burn(ctx, sender: ctx.msg_sender(), amount0, amount1, to) 217 │ │ return (amount0, amount1) - │ ╰─────────────────────────────────^ attributes hash: 6944915226485076500 + │ ╰─────────────────────────────────^ attributes hash: 9480812542525876292 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 7213..7217, + }, ), ctx_decl: Some( Mutable, @@ -3123,18 +3174,21 @@ note: note: ┌─ uniswap.fe:222:5 │ -222 │ ╭ pub fn swap(self, ctx: Context, amount0_out: u256, amount1_out: u256, to: address): +222 │ ╭ pub fn swap(mut self, ctx: Context, amount0_out: u256, amount1_out: u256, to: address): 223 │ │ assert amount0_out > 0 or amount1_out > 0, "UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT" 224 │ │ let reserve0: u256 = self.reserve0 225 │ │ let reserve1: u256 = self.reserve1 · │ 255 │ │ self._update(ctx, balance0, balance1, reserve0, reserve1) 256 │ │ emit Swap(ctx, sender: ctx.msg_sender(), amount0_in, amount1_in, amount0_out, amount1_out, to) - │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────^ attributes hash: 10366329877988676622 + │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────^ attributes hash: 2939999212869493409 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 8992..8996, + }, ), ctx_decl: Some( Mutable, @@ -3764,17 +3818,20 @@ note: note: ┌─ uniswap.fe:259:5 │ -259 │ ╭ pub fn skim(self, ctx: Context, to: address): +259 │ ╭ pub fn skim(mut self, ctx: Context, to: address): 260 │ │ let token0: ERC20 = ERC20(ctx, self.token0) # gas savings 261 │ │ let token1: ERC20 = ERC20(ctx, self.token1) # gas savings 262 │ │ 263 │ │ token0.transfer(to, token0.balanceOf(ctx.self_address()) - self.reserve0) 264 │ │ token1.transfer(to, token1.balanceOf(ctx.self_address()) - self.reserve1) - │ ╰─────────────────────────────────────────────────────────────────────────────────^ attributes hash: 11047766956698411209 + │ ╰─────────────────────────────────────────────────────────────────────────────────^ attributes hash: 5316608983835287591 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 10918..10922, + }, ), ctx_decl: Some( Mutable, @@ -3935,18 +3992,21 @@ note: note: ┌─ uniswap.fe:267:5 │ -267 │ ╭ pub fn sync(self, ctx: Context): +267 │ ╭ pub fn sync(mut self, ctx: Context): 268 │ │ let token0: ERC20 = ERC20(ctx, self.token0) 269 │ │ let token1: ERC20 = ERC20(ctx, self.token1) 270 │ │ self._update(ctx, · │ 273 │ │ reserve0: self.reserve0, 274 │ │ reserve1: self.reserve1) - │ ╰─────────────────────────────────────────────^ attributes hash: 17228436346762880410 + │ ╰─────────────────────────────────────────────^ attributes hash: 10932442012863233492 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 11309..11313, + }, ), ctx_decl: Some( Mutable, @@ -4112,11 +4172,14 @@ note: │ 294 │ ╭ pub fn fee_to(self) -> address: 295 │ │ return self.fee_to - │ ╰──────────────────────────^ attributes hash: 12485079837452748334 + │ ╰──────────────────────────^ attributes hash: 4904320013011961635 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 12113..12117, + }, ), ctx_decl: None, params: [], @@ -4144,11 +4207,14 @@ note: │ 297 │ ╭ pub fn fee_to_setter(self) -> address: 298 │ │ return self.fee_to_setter - │ ╰─────────────────────────────────^ attributes hash: 12485079837452748334 + │ ╰─────────────────────────────────^ attributes hash: 5518987369979851307 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 12184..12188, + }, ), ctx_decl: None, params: [], @@ -4176,11 +4242,14 @@ note: │ 300 │ ╭ pub fn all_pairs_length(self) -> u256: 301 │ │ return self.pair_counter - │ ╰────────────────────────────────^ attributes hash: 9289100627868228400 + │ ╰────────────────────────────────^ attributes hash: 15715561092694977964 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: Ref, + span: 12265..12269, + }, ), ctx_decl: None, params: [], @@ -4208,18 +4277,21 @@ note: note: ┌─ uniswap.fe:303:5 │ -303 │ ╭ pub fn create_pair(self, ctx: Context, _ token_a: address, _ token_b: address) -> address: +303 │ ╭ pub fn create_pair(mut self, ctx: Context, _ token_a: address, _ token_b: address) -> address: 304 │ │ assert token_a != token_b, "UniswapV2: IDENTICAL_ADDRESSES" 305 │ │ 306 │ │ let token0: address = token_a if token_a < token_b else token_b · │ 320 │ │ emit PairCreated(ctx, token0, token1, pair: address(pair), index: self.pair_counter) 321 │ │ return address(pair) - │ ╰────────────────────────────^ attributes hash: 4826723925688846256 + │ ╰────────────────────────────^ attributes hash: 5900270013228879828 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 12341..12345, + }, ), ctx_decl: Some( Mutable, @@ -4642,14 +4714,17 @@ note: note: ┌─ uniswap.fe:323:5 │ -323 │ ╭ pub fn set_fee_to(self, ctx: Context, fee_to: address): +323 │ ╭ pub fn set_fee_to(mut self, ctx: Context, fee_to: address): 324 │ │ assert ctx.msg_sender() == self.fee_to_setter, "UniswapV2: FORBIDDEN" 325 │ │ self.fee_to = fee_to - │ ╰────────────────────────────^ attributes hash: 9194981006489172433 + │ ╰────────────────────────────^ attributes hash: 10388358816800266756 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 13309..13313, + }, ), ctx_decl: Some( Mutable, @@ -4727,14 +4802,17 @@ note: note: ┌─ uniswap.fe:327:5 │ -327 │ ╭ pub fn set_fee_to_setter(self, ctx: Context, fee_to_setter: address): +327 │ ╭ pub fn set_fee_to_setter(mut self, ctx: Context, fee_to_setter: address): 328 │ │ assert ctx.msg_sender() == fee_to_setter, "UniswapV2: FORBIDDEN" 329 │ │ self.fee_to_setter = fee_to_setter - │ ╰──────────────────────────────────────────^ attributes hash: 1679766870695458002 + │ ╰──────────────────────────────────────────^ attributes hash: 2480911855679723100 │ = FunctionSignature { self_decl: Some( - Ref, + SelfDecl { + kind: MutRef, + span: 13488..13492, + }, ), ctx_decl: Some( Mutable, diff --git a/crates/analyzer/tests/snapshots/errors__assign_type_mismatch.snap b/crates/analyzer/tests/snapshots/errors__assign_type_mismatch.snap index 6043b87fa1..0fe8959470 100644 --- a/crates/analyzer/tests/snapshots/errors__assign_type_mismatch.snap +++ b/crates/analyzer/tests/snapshots/errors__assign_type_mismatch.snap @@ -9,6 +9,6 @@ error: mismatched types 4 │ x = address(0) │ ^ ---------- this value has incompatible type `address` │ │ - │ this variable has type `u256` + │ this has type `u256` diff --git a/crates/analyzer/tests/snapshots/errors__call_non_pub_fn_on_external_contract.snap b/crates/analyzer/tests/snapshots/errors__call_non_pub_fn_on_external_contract.snap index 08f85c4dcb..e12817b6fa 100644 --- a/crates/analyzer/tests/snapshots/errors__call_non_pub_fn_on_external_contract.snap +++ b/crates/analyzer/tests/snapshots/errors__call_non_pub_fn_on_external_contract.snap @@ -3,6 +3,14 @@ source: crates/analyzer/tests/errors.rs expression: "error_string(&path, test_files::fixture(path))" --- +error: cannot modify `self`, as it is not mutable + ┌─ compile_errors/call_non_pub_fn_on_external_contract.fe:6:6 + │ +5 │ fn do_private_thingz(self): + │ ---- consider changing this to be mutable: `mut self` +6 │ self.val = 100 + │ ^^^^ not mutable + error: the function `do_private_thingz` on `contract Foo` is private ┌─ compile_errors/call_non_pub_fn_on_external_contract.fe:10:26 │ diff --git a/crates/analyzer/tests/snapshots/errors__ctx_missing_internal_call.snap b/crates/analyzer/tests/snapshots/errors__ctx_missing_internal_call.snap index 9b291de008..3084e7f62a 100644 --- a/crates/analyzer/tests/snapshots/errors__ctx_missing_internal_call.snap +++ b/crates/analyzer/tests/snapshots/errors__ctx_missing_internal_call.snap @@ -12,4 +12,12 @@ error: `bar` expects 1 argument, but 0 were provided 10 │ self.favorite_number = bar() │ -- supplied 0 arguments +error: cannot modify `self`, as it is not mutable + ┌─ compile_errors/ctx_missing_internal_call.fe:10:9 + │ + 9 │ pub fn baz(self, ctx: Context): + │ ---- consider changing this to be mutable: `mut self` +10 │ self.favorite_number = bar() + │ ^^^^ not mutable + diff --git a/crates/analyzer/tests/snapshots/errors__ctx_passed_external_call.snap b/crates/analyzer/tests/snapshots/errors__ctx_passed_external_call.snap index ae0746c083..6c06523aa9 100644 --- a/crates/analyzer/tests/snapshots/errors__ctx_passed_external_call.snap +++ b/crates/analyzer/tests/snapshots/errors__ctx_passed_external_call.snap @@ -11,4 +11,13 @@ error: `bar` expects 0 arguments, but 1 was provided │ │ │ expects 0 arguments +error: cannot modify `self`, as it is not mutable + ┌─ compile_errors/ctx_passed_external_call.fe:13:9 + │ +11 │ pub fn baz(self, ctx: Context): + │ ---- consider changing this to be mutable: `mut self` +12 │ let foo: Foo = Foo.create(ctx, 0) +13 │ self.favorite_number = foo.bar(ctx) + │ ^^^^ not mutable + diff --git a/crates/analyzer/tests/snapshots/errors__missing_return.snap b/crates/analyzer/tests/snapshots/errors__missing_return.snap index 4f4085dce9..9c08757921 100644 --- a/crates/analyzer/tests/snapshots/errors__missing_return.snap +++ b/crates/analyzer/tests/snapshots/errors__missing_return.snap @@ -11,4 +11,12 @@ error: function body is missing a return or revert statement │ │ │ all paths of this function must `return` or `revert` +error: cannot modify `self.baz`, as it is not mutable + ┌─ compile_errors/missing_return.fe:5:9 + │ +4 │ pub fn bar(self) -> u256: + │ ---- consider changing this to be mutable: `mut self` +5 │ self.baz[0] = 1 + │ ^^^^^^^^ not mutable + diff --git a/crates/analyzer/tests/snapshots/errors__self_misuse.snap b/crates/analyzer/tests/snapshots/errors__self_misuse.snap index 7b1178b357..36029fbd6b 100644 --- a/crates/analyzer/tests/snapshots/errors__self_misuse.snap +++ b/crates/analyzer/tests/snapshots/errors__self_misuse.snap @@ -15,6 +15,14 @@ error: `self` can only be used in contract or struct functions 3 │ self = 5 │ ^^^^ not allowed in functions defined outside of a contract or struct +error: cannot modify `s`, as it is not mutable + ┌─ compile_errors/self_misuse.fe:6:3 + │ +5 │ fn change_x(_ s: S): + │ - consider changing this to be mutable: `mut s` +6 │ s.x = 100 + │ ^ not mutable + error: `self` is not callable ┌─ compile_errors/self_misuse.fe:15:5 │ diff --git a/crates/analyzer/tests/snapshots/errors__self_mut_mismatch.snap b/crates/analyzer/tests/snapshots/errors__self_mut_mismatch.snap index 5437b5e410..76ba46ebe0 100644 --- a/crates/analyzer/tests/snapshots/errors__self_mut_mismatch.snap +++ b/crates/analyzer/tests/snapshots/errors__self_mut_mismatch.snap @@ -3,10 +3,31 @@ source: crates/analyzer/tests/errors.rs expression: "error_string(&path, test_files::fixture(path))" --- -error: bad call to mut self fn +error: function `set_things` requires `mut self` ┌─ compile_errors/self_mut_mismatch.fe:5:14 │ +4 │ fn foo(self): + │ ---- consider changing this to be mutable: `mut self` 5 │ self.set_things(x: 10) - │ ^^^^^^^^^^ function requires mut self + │ ---- ^^^^^^^^^^ requires `mut self` + │ │ + │ not mutable + +error: cannot modify `self`, as it is not mutable + ┌─ compile_errors/self_mut_mismatch.fe:6:9 + │ +4 │ fn foo(self): + │ ---- consider changing this to be mutable: `mut self` +5 │ self.set_things(x: 10) +6 │ self.x = 100 + │ ^^^^ not mutable + +error: cannot modify `self`, as it is not mutable + ┌─ compile_errors/self_mut_mismatch.fe:19:9 + │ +18 │ pub fn get_name(self) -> String<100>: + │ ---- consider changing this to be mutable: `mut self` +19 │ self.name = "shouldnt work" + │ ^^^^ not mutable diff --git a/crates/test-files/fixtures/demos/uniswap.fe b/crates/test-files/fixtures/demos/uniswap.fe index 42b6b3edcc..2d47050db2 100644 --- a/crates/test-files/fixtures/demos/uniswap.fe +++ b/crates/test-files/fixtures/demos/uniswap.fe @@ -62,7 +62,7 @@ contract UniswapV2Pair: reserve0: u256 reserve1: u256 - pub fn __init__(self, ctx: Context): + pub fn __init__(mut self, ctx: Context): self.factory = ctx.msg_sender() pub fn factory(self) -> address: @@ -74,36 +74,36 @@ contract UniswapV2Pair: pub fn token1(self) -> address: return self.token1 - fn _mint(self, ctx: Context, to: address, value: u256): + fn _mint(mut self, ctx: Context, to: address, value: u256): self.total_supply = self.total_supply + value self.balances[to] = self.balances[to] + value emit Transfer(ctx, from: address(0), to, value) - fn _burn(self, ctx: Context, from: address, value: u256): + fn _burn(mut self, ctx: Context, from: address, value: u256): self.balances[from] = self.balances[from] - value self.total_supply = self.total_supply - value emit Transfer(ctx, from, to: address(0), value) - fn _approve(self, ctx: Context, owner: address, spender: address, value: u256): + fn _approve(mut self, ctx: Context, owner: address, spender: address, value: u256): self.allowances[owner][spender] = value emit Approval(ctx, owner, spender, value) - fn _transfer(self, ctx: Context, from: address, to: address, value: u256): + fn _transfer(mut self, ctx: Context, from: address, to: address, value: u256): self.balances[from] = self.balances[from] - value self.balances[to] = self.balances[to] + value emit Transfer(ctx, from, to, value) - pub fn approve(self, ctx: Context, spender: address, value: u256) -> bool: + pub fn approve(mut self, ctx: Context, spender: address, value: u256) -> bool: self._approve(ctx, owner: ctx.msg_sender(), spender, value) return true - pub fn transfer(self, ctx: Context, to: address, value: u256) -> bool: + pub fn transfer(mut self, ctx: Context, to: address, value: u256) -> bool: self._transfer(ctx, from: ctx.msg_sender(), to, value) return true - pub fn transferFrom(self, ctx: Context, from: address, to: address, value: u256) -> bool: + pub fn transferFrom(mut self, ctx: Context, from: address, to: address, value: u256) -> bool: assert self.allowances[from][ctx.msg_sender()] >= value self.allowances[from][ctx.msg_sender()] = self.allowances[from][ctx.msg_sender()] - value self._transfer(ctx, from, to, value) @@ -116,13 +116,13 @@ contract UniswapV2Pair: return (self.reserve0, self.reserve1, self.block_timestamp_last) # called once by the factory at time of deployment - pub fn initialize(self, ctx: Context, token0: address, token1: address): + pub fn initialize(mut self, ctx: Context, token0: address, token1: address): assert ctx.msg_sender() == self.factory, "UniswapV2: FORBIDDEN" self.token0 = token0 self.token1 = token1 # update reserves and, on the first call per block, price accumulators - fn _update(self, ctx: Context, balance0: u256, balance1: u256, reserve0: u256, reserve1: u256): + fn _update(mut self, ctx: Context, balance0: u256, balance1: u256, reserve0: u256, reserve1: u256): # changed from u32s let block_timestamp: u256 = ctx.block_timestamp() % 2**32 # TODO: reproduce desired overflow (https://github.com/ethereum/fe/issues/286) @@ -138,7 +138,7 @@ contract UniswapV2Pair: emit Sync(ctx, reserve0: self.reserve0, reserve1: self.reserve1) # if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k) - fn _mint_fee(self, ctx: Context, reserve0: u256, reserve1: u256) -> bool: + fn _mint_fee(mut self, ctx: Context, reserve0: u256, reserve1: u256) -> bool: let fee_to: address = UniswapV2Factory(ctx, self.factory).fee_to() let fee_on: bool = fee_to != address(0) let k_last: u256 = self.k_last # gas savings @@ -158,7 +158,7 @@ contract UniswapV2Pair: return fee_on # this low-level function should be called from a contract which performs important safety checks - pub fn mint(self, ctx: Context, to: address) -> u256: + pub fn mint(mut self, ctx: Context, to: address) -> u256: let MINIMUM_LIQUIDITY: u256 = 1000 let reserve0: u256 = self.reserve0 let reserve1: u256 = self.reserve1 @@ -188,7 +188,7 @@ contract UniswapV2Pair: return liquidity # this low-level function should be called from a contract which performs important safety checks - pub fn burn(self, ctx: Context, to: address) -> (u256, u256): + pub fn burn(mut self, ctx: Context, to: address) -> (u256, u256): let reserve0: u256 = self.reserve0 let reserve1: u256 = self.reserve1 let token0: ERC20 = ERC20(ctx, self.token0) @@ -219,7 +219,7 @@ contract UniswapV2Pair: # this low-level function should be called from a contract which performs important safety checks # TODO: add support for the bytes type (https://github.com/ethereum/fe/issues/280) # pub fn swap(amount0_out: u256, amount1_out: u256, to: address, data: bytes): - pub fn swap(self, ctx: Context, amount0_out: u256, amount1_out: u256, to: address): + pub fn swap(mut self, ctx: Context, amount0_out: u256, amount1_out: u256, to: address): assert amount0_out > 0 or amount1_out > 0, "UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT" let reserve0: u256 = self.reserve0 let reserve1: u256 = self.reserve1 @@ -256,7 +256,7 @@ contract UniswapV2Pair: emit Swap(ctx, sender: ctx.msg_sender(), amount0_in, amount1_in, amount0_out, amount1_out, to) # force balances to match reserves - pub fn skim(self, ctx: Context, to: address): + pub fn skim(mut self, ctx: Context, to: address): let token0: ERC20 = ERC20(ctx, self.token0) # gas savings let token1: ERC20 = ERC20(ctx, self.token1) # gas savings @@ -264,7 +264,7 @@ contract UniswapV2Pair: token1.transfer(to, token1.balanceOf(ctx.self_address()) - self.reserve1) # force reserves to match balances - pub fn sync(self, ctx: Context): + pub fn sync(mut self, ctx: Context): let token0: ERC20 = ERC20(ctx, self.token0) let token1: ERC20 = ERC20(ctx, self.token1) self._update(ctx, @@ -288,7 +288,7 @@ contract UniswapV2Factory: pair: address index: u256 - pub fn __init__(self, _ fee_to_setter: address): + pub fn __init__(mut self, _ fee_to_setter: address): self.fee_to_setter = fee_to_setter pub fn fee_to(self) -> address: @@ -300,7 +300,7 @@ contract UniswapV2Factory: pub fn all_pairs_length(self) -> u256: return self.pair_counter - pub fn create_pair(self, ctx: Context, _ token_a: address, _ token_b: address) -> address: + pub fn create_pair(mut self, ctx: Context, _ token_a: address, _ token_b: address) -> address: assert token_a != token_b, "UniswapV2: IDENTICAL_ADDRESSES" let token0: address = token_a if token_a < token_b else token_b @@ -320,11 +320,11 @@ contract UniswapV2Factory: emit PairCreated(ctx, token0, token1, pair: address(pair), index: self.pair_counter) return address(pair) - pub fn set_fee_to(self, ctx: Context, fee_to: address): + pub fn set_fee_to(mut self, ctx: Context, fee_to: address): assert ctx.msg_sender() == self.fee_to_setter, "UniswapV2: FORBIDDEN" self.fee_to = fee_to - pub fn set_fee_to_setter(self, ctx: Context, fee_to_setter: address): + pub fn set_fee_to_setter(mut self, ctx: Context, fee_to_setter: address): assert ctx.msg_sender() == fee_to_setter, "UniswapV2: FORBIDDEN" self.fee_to_setter = fee_to_setter diff --git a/crates/test-files/fixtures/features/two_contracts.fe b/crates/test-files/fixtures/features/two_contracts.fe index 552c27fb4e..a3c854c5ff 100644 --- a/crates/test-files/fixtures/features/two_contracts.fe +++ b/crates/test-files/fixtures/features/two_contracts.fe @@ -3,7 +3,7 @@ use std::context::Context contract Foo: other: Bar - pub fn __init__(self, ctx: Context): + pub fn __init__(mut self, ctx: Context): self.other = Bar.create(ctx, 0) pub fn foo(self, ctx: Context) -> u256: @@ -16,7 +16,7 @@ contract Foo: contract Bar: other: Foo - pub fn set_foo_addr(self, ctx: Context, _ addr: address): + pub fn set_foo_addr(mut self, ctx: Context, _ addr: address): self.other = Foo(ctx, addr) pub fn answer(self) -> u256: diff --git a/crates/test-files/fixtures/features/type_aliases.fe b/crates/test-files/fixtures/features/type_aliases.fe index 80738f72b9..923266b9d1 100644 --- a/crates/test-files/fixtures/features/type_aliases.fe +++ b/crates/test-files/fixtures/features/type_aliases.fe @@ -14,14 +14,14 @@ contract Forum: authors: AuthorPosts scoreboard: Scoreboard - pub fn post(self, ctx: Context, body: PostBody): + pub fn post(mut self, ctx: Context, body: PostBody): # id: PostId = keccak256(body.abi_encode()) let id: PostId = 0 self.posts[id] = body self.authors[ctx.msg_sender()] self.scoreboard[id] = 0 - pub fn upvote(self, id: PostId) -> Score: + pub fn upvote(mut self, id: PostId) -> Score: let score: Score = self.scoreboard[id] + 1 self.scoreboard[id] = score return score