diff --git a/src/bin/languageserver/mod.rs b/src/bin/languageserver/mod.rs index 79f02833a..2cf7c19b8 100644 --- a/src/bin/languageserver/mod.rs +++ b/src/bin/languageserver/mod.rs @@ -1644,7 +1644,7 @@ impl<'a> Builder<'a> { } for (i, constant) in self.ns.constants.iter().enumerate() { - let samptb = symtable::Symtable::new(); + let samptb = symtable::Symtable::default(); self.contract_variable(constant, &samptb, None, i); } @@ -1676,7 +1676,7 @@ impl<'a> Builder<'a> { } for (i, variable) in contract.variables.iter().enumerate() { - let symtable = symtable::Symtable::new(); + let symtable = symtable::Symtable::default(); self.contract_variable(variable, &symtable, Some(ci), i); } diff --git a/src/codegen/revert.rs b/src/codegen/revert.rs index b436346fa..1c0750e1f 100644 --- a/src/codegen/revert.rs +++ b/src/codegen/revert.rs @@ -326,7 +326,7 @@ pub(super) fn revert( .collect::>(); if opt.log_runtime_errors { - match (error_no, exprs.get(0)) { + match (error_no, exprs.first()) { // In the case of Error(string), we can print the reason (None, Some(expr)) => { let prefix = b"runtime_error: "; @@ -369,7 +369,7 @@ pub(super) fn revert( } } - let error = match (*error_no, exprs.get(0)) { + let error = match (*error_no, exprs.first()) { // Having an error number requires a custom error (Some(error_no), _) => SolidityError::Custom { error_no, exprs }, // No error number but an expression requires Error(String) diff --git a/src/codegen/statements/try_catch.rs b/src/codegen/statements/try_catch.rs index cfad6deb5..c15221628 100644 --- a/src/codegen/statements/try_catch.rs +++ b/src/codegen/statements/try_catch.rs @@ -290,7 +290,7 @@ fn exec_try( call_args, .. } => { - let address_res = match try_stmt.returns.get(0) { + let address_res = match try_stmt.returns.first() { Some((Some(pos), _)) => *pos, _ => vartab.temp_anonymous(&Type::Contract(*contract_no)), }; diff --git a/src/emit/polkadot/storage.rs b/src/emit/polkadot/storage.rs index f74a39d78..fadc9341d 100644 --- a/src/emit/polkadot/storage.rs +++ b/src/emit/polkadot/storage.rs @@ -754,7 +754,7 @@ impl StorageSlot for PolkadotTarget { } } Type::Struct(str_ty) => { - for (_, field) in str_ty.definition(ns).fields.iter().enumerate() { + for field in &str_ty.definition(ns).fields { self.storage_delete_slot(bin, &field.ty, slot, slot_ptr, function, ns); if !field.ty.is_reference_type(ns) diff --git a/src/sema/ast.rs b/src/sema/ast.rs index d8aa32bf5..e81229454 100644 --- a/src/sema/ast.rs +++ b/src/sema/ast.rs @@ -457,7 +457,7 @@ impl Function { has_body: false, is_override: None, body: Vec::new(), - symtable: Symtable::new(), + symtable: Symtable::default(), emits_events: Vec::new(), mangled_name, annotations: ConstructorAnnotations::default(), diff --git a/src/sema/contracts.rs b/src/sema/contracts.rs index 4f80eb633..086f3d288 100644 --- a/src/sema/contracts.rs +++ b/src/sema/contracts.rs @@ -217,7 +217,7 @@ fn resolve_base_args(contracts: &[ContractDefinition], file_no: usize, ns: &mut .position(|e| e.contract_no == base_no) { if let Some(args) = &base.args { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); // find constructor which matches this if let Ok((Some(constructor_no), args)) = match_constructor_to_args( diff --git a/src/sema/expression/literals.rs b/src/sema/expression/literals.rs index 0f1c5e4ec..6efc2f369 100644 --- a/src/sema/expression/literals.rs +++ b/src/sema/expression/literals.rs @@ -826,7 +826,7 @@ fn check_subarrays<'a>( flatten: &mut Vec<&'a pt::Expression>, diagnostics: &mut Diagnostics, ) -> Result<(), ()> { - if let Some(pt::Expression::ArrayLiteral(_, first)) = exprs.get(0) { + if let Some(pt::Expression::ArrayLiteral(_, first)) = exprs.first() { // ensure all elements are array literals of the same length check_subarrays(first, dims, flatten, diagnostics)?; diff --git a/src/sema/mod.rs b/src/sema/mod.rs index e55aa2422..6b37f9cdb 100644 --- a/src/sema/mod.rs +++ b/src/sema/mod.rs @@ -159,7 +159,7 @@ fn sema_file(file: &ResolvedFile, resolver: &mut FileResolver, ns: &mut ast::Nam &item.doccomments, None, ns, - &mut Symtable::new(), + &mut Symtable::default(), ); } _ => (), diff --git a/src/sema/mutability.rs b/src/sema/mutability.rs index d5b32d1b3..d6976403b 100644 --- a/src/sema/mutability.rs +++ b/src/sema/mutability.rs @@ -235,13 +235,13 @@ fn check_mutability(func: &Function, ns: &Namespace) -> Diagnostics { SolanaAccount { loc: Loc::Codegen, is_writer: true, - /// With a @payer annotation, the account is created on-chain and needs a signer. The client - /// provides an address that does not exist yet, so SystemProgram.CreateAccount is called - /// on-chain. - /// - /// However, if a @seed is also provided, the program can sign for the account - /// with the seed using program derived address (pda) when SystemProgram.CreateAccount is called, - /// so no signer is required from the client. + // With a @payer annotation, the account is created on-chain and needs a signer. The client + // provides an address that does not exist yet, so SystemProgram.CreateAccount is called + // on-chain. + // + // However, if a @seed is also provided, the program can sign for the account + // with the seed using program derived address (pda) when SystemProgram.CreateAccount is called, + // so no signer is required from the client. is_signer: func.has_payer_annotation() && !func.has_seed_annotation(), generated: true, }, diff --git a/src/sema/namespace.rs b/src/sema/namespace.rs index 83688fca6..639908110 100644 --- a/src/sema/namespace.rs +++ b/src/sema/namespace.rs @@ -35,7 +35,7 @@ impl Namespace { /// Create a namespace and populate with the parameters for the target pub fn new(target: Target) -> Self { let (address_length, value_length) = match target { - Target::EVM => (20, 16), + Target::EVM => (20, 32), Target::Polkadot { address_length, value_length, @@ -1310,7 +1310,7 @@ impl Namespace { } } - if let Some(contract_name) = namespace.get(0) { + if let Some(contract_name) = namespace.first() { contract_no = match self .variable_symbols .get(&(import_file_no, None, contract_name.name.clone())) @@ -1524,7 +1524,7 @@ impl Namespace { expr: &pt::Expression, diagnostics: &mut Diagnostics, ) -> Result { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut context = ExprContext { file_no, unchecked: true, diff --git a/src/sema/statements.rs b/src/sema/statements.rs index 5666da13f..fa2db59ca 100644 --- a/src/sema/statements.rs +++ b/src/sema/statements.rs @@ -38,7 +38,7 @@ pub fn resolve_function_body( function_no: usize, ns: &mut Namespace, ) -> Result<(), ()> { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut res = Vec::new(); let mut context = ExprContext { file_no, diff --git a/src/sema/symtable.rs b/src/sema/symtable.rs index ea7248487..e3ede0532 100644 --- a/src/sema/symtable.rs +++ b/src/sema/symtable.rs @@ -93,15 +93,6 @@ pub struct Symtable { } impl Symtable { - pub fn new() -> Self { - Symtable { - vars: IndexMap::new(), - arguments: Vec::new(), - returns: Vec::new(), - scopes: Vec::new(), - } - } - pub fn add( &mut self, id: &pt::Identifier, diff --git a/src/sema/tests/mod.rs b/src/sema/tests/mod.rs index 5e6f6722e..d1a9d1dc9 100644 --- a/src/sema/tests/mod.rs +++ b/src/sema/tests/mod.rs @@ -640,7 +640,7 @@ fn get_import_path() { let ns = parse_and_resolve(OsStr::new("example.sol"), &mut cache, Target::EVM); - let file = ns.files.get(0); + let file = ns.files.first(); assert!(file.is_some()); if let Some(file) = file { let import_path = cache.get_import_path(file.import_no.unwrap()); @@ -648,7 +648,7 @@ fn get_import_path() { } let ns = parse_and_resolve(OsStr::new("incrementer.sol"), &mut cache, Target::EVM); - let file = ns.files.get(0); + let file = ns.files.first(); assert!(file.is_some()); if let Some(file) = file { let import_path = cache.get_import_path(file.import_no.unwrap()); diff --git a/src/sema/variables.rs b/src/sema/variables.rs index 2ac6ab5f0..8ebea6971 100644 --- a/src/sema/variables.rs +++ b/src/sema/variables.rs @@ -32,7 +32,7 @@ pub fn contract_variables<'a>( file_no: usize, ns: &mut Namespace, ) -> Vec> { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut delayed = Vec::new(); for part in &def.parts { @@ -447,7 +447,7 @@ pub fn variable_decl<'a>( // If the variable is an array or mapping, the accessor function takes mapping keys // or array indices as arguments, and returns the dereferenced value - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut context = ExprContext::default(); context.enter_scope(); let mut params = Vec::new(); @@ -784,7 +784,7 @@ pub fn resolve_initializers( file_no: usize, ns: &mut Namespace, ) { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut diagnostics = Diagnostics::default(); for DelayedResolveInitializer { diff --git a/src/sema/yul/functions.rs b/src/sema/yul/functions.rs index 3f5ee9420..0de74bfd3 100644 --- a/src/sema/yul/functions.rs +++ b/src/sema/yul/functions.rs @@ -239,7 +239,7 @@ pub(crate) fn resolve_function_definition( context: &mut ExprContext, ns: &mut Namespace, ) -> Result { - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); context.enter_scope(); let prev_yul_function = context.yul_function; diff --git a/src/sema/yul/tests/expression.rs b/src/sema/yul/tests/expression.rs index 750711c3b..65e0041c8 100644 --- a/src/sema/yul/tests/expression.rs +++ b/src/sema/yul/tests/expression.rs @@ -25,7 +25,7 @@ use std::sync::Arc; fn resolve_bool_literal() { let mut ctx = ExprContext::default(); ctx.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::Solana); @@ -66,7 +66,7 @@ fn resolve_bool_literal() { fn resolve_number_literal() { let mut ctx = ExprContext::default(); ctx.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let loc = Loc::File(0, 3, 5); @@ -124,7 +124,7 @@ fn resolve_number_literal() { fn resolve_hex_number_literal() { let mut ctx = ExprContext::default(); ctx.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::EVM); @@ -170,7 +170,7 @@ fn resolve_hex_number_literal() { fn resolve_hex_string_literal() { let mut ctx = ExprContext::default(); ctx.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::EVM); @@ -237,7 +237,7 @@ fn resolve_hex_string_literal() { fn resolve_string_literal() { let mut ctx = ExprContext::default(); ctx.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::Solana); @@ -268,7 +268,7 @@ fn resolve_string_literal() { fn resolve_variable_local() { let mut context = ExprContext::default(); context.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::EVM); let loc = Loc::File(1, 2, 3); @@ -346,7 +346,7 @@ fn resolve_variable_contract() { }; context.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::EVM); let loc = Loc::File(0, 2, 3); @@ -543,7 +543,7 @@ fn resolve_variable_contract() { fn function_call() { let mut context = ExprContext::default(); context.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); function_table.enter_scope(); let mut ns = Namespace::new(Target::EVM); @@ -739,7 +739,7 @@ fn function_call() { fn check_arguments() { let mut context = ExprContext::default(); context.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); function_table.enter_scope(); let mut ns = Namespace::new(Target::EVM); @@ -896,7 +896,7 @@ fn test_member_access() { }; context.enter_scope(); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); let mut function_table = FunctionsTable::new(0); let mut ns = Namespace::new(Target::EVM); let loc = Loc::File(0, 2, 3); @@ -1045,7 +1045,7 @@ fn test_check_types() { read: false, }); ns.contracts.push(contract); - let mut symtable = Symtable::new(); + let mut symtable = Symtable::default(); symtable.add( &Identifier { loc, diff --git a/tests/codegen_testcases/yul/evm_builtin.sol b/tests/codegen_testcases/yul/evm_builtin.sol index 1adb28f38..5c863ed09 100644 --- a/tests/codegen_testcases/yul/evm_builtin.sol +++ b/tests/codegen_testcases/yul/evm_builtin.sol @@ -11,16 +11,16 @@ contract Testing { // CHECK: (sext uint256 uint160((load (builtin GetAddress ())))) let b := address() - // CHECK: ty:uint256 %c = (sext uint256 (builtin Balance (address((trunc uint160 (arg #0)))))) + // CHECK: ty:uint256 %c = uint256((builtin Balance (address((trunc uint160 (arg #0)))))) let c := balance(arg1) - // CHECK: ty:uint256 %d = (sext uint256 (builtin Balance ((load (builtin GetAddress ()))))) + // CHECK: ty:uint256 %d = uint256((builtin Balance ((load (builtin GetAddress ()))))) let d := selfbalance() // CHECK: ty:uint256 %e = (sext uint256 uint160((builtin Sender ()))) let e := caller() - // CHECK: ty:uint256 %f = (sext uint256 (builtin Value ())) + // CHECK: ty:uint256 %f = uint256((builtin Value ())) let f := callvalue() // CHECK: ty:uint256 %g = (zext uint256 (builtin Gasprice ())) diff --git a/tests/contract_testcases/evm/comment_tests.sol b/tests/contract_testcases/evm/comment_tests.sol index 083792a1c..4c3efb060 100644 --- a/tests/contract_testcases/evm/comment_tests.sol +++ b/tests/contract_testcases/evm/comment_tests.sol @@ -677,11 +677,9 @@ function _approve( }// // }/**//**//**//**//**//**//**/// + // ---- Expect: diagnostics ---- -// warning: 195:50-56: conversion truncates uint256 to uint128, as value is type uint128 on target EVM -// warning: 268:17-25: function parameter 'weiValue' is unused // warning: 269:23-35: function parameter 'errorMessage' is unused -// warning: 276:70-78: conversion truncates uint256 to uint128, as value is type uint128 on target EVM // warning: 321:9-17: 'internal': visibility for constructors is ignored // warning: 386:9-61: storage variable '_isExcluded' has never been used // warning: 390:9-51: storage variable 'MAX' has been assigned, but never read diff --git a/tests/solana.rs b/tests/solana.rs index 8acff3b7f..38882d6be 100644 --- a/tests/solana.rs +++ b/tests/solana.rs @@ -1125,7 +1125,7 @@ fn create_program_address(program_id: &Account, seeds: &[&[u8]]) -> Pubkey { let hash = hasher.finalize(); - let new_address: [u8; 32] = hash.try_into().unwrap(); + let new_address: [u8; 32] = hash.into(); // the real runtime does checks if this address exists on the ed25519 curve @@ -1268,7 +1268,7 @@ fn sol_invoke_signed_c( let hash = hasher.finalize(); - let new_address: [u8; 32] = hash.try_into().unwrap(); + let new_address: [u8; 32] = hash.into(); println!( "creating account {} with space {} owner {}",