diff --git a/src/sema/diagnostics.rs b/src/sema/diagnostics.rs index a98f80d941..a4a3046599 100644 --- a/src/sema/diagnostics.rs +++ b/src/sema/diagnostics.rs @@ -144,67 +144,6 @@ impl Diagnostics { self.contents.sort(); self.contents.dedup(); } - - /// Find overlapping errors and retain the diagnostic with the smallest range - pub fn remove_overlapping(&mut self) { - if self.contents.is_empty() { - return; - } - - type Iv = Interval; - - // in data val is the diagnostic index - let data: Vec = self - .contents - .iter() - .enumerate() - .map(|(index, diag)| Iv { - start: diag.loc.start(), - stop: diag.loc.end(), - val: index, - }) - .collect(); - - let laps = Lapper::new(data); - - let mut remove_list = Vec::new(); - - for depth in laps.depth() { - // in depth val is the number of entries for the depth - if depth.val > 1 { - // we have multiple diagnostic for range - let mut for_range: Vec<_> = laps.find(depth.start, depth.stop).collect(); - - assert_eq!(for_range.len(), depth.val); - - for_range.sort_by(|a, b| { - // prefer errors over warnings - let cmp = self.contents[a.val].level.cmp(&self.contents[b.val].level); - - if cmp != Ordering::Equal { - cmp - } else { - // else prefer shorter range over longer - (a.stop - a.start).cmp(&(b.stop - b.start)) - } - }); - - // we may up with dups in remove_list, but that's not really a problem - for_range[1..].iter().for_each(|v| remove_list.push(v.val)); - } - } - - // remove all diagnostics in remove_list - let mut contents = Vec::new(); - - swap(&mut self.contents, &mut contents); - - for (index, diag) in contents.into_iter().enumerate() { - if !remove_list.contains(&index) { - self.contents.push(diag); - } - } - } } fn convert_diagnostic( diff --git a/src/sema/mutability.rs b/src/sema/mutability.rs index 3e44b2a729..e5afa5a661 100644 --- a/src/sema/mutability.rs +++ b/src/sema/mutability.rs @@ -183,8 +183,6 @@ fn check_mutability(func: &Function, ns: &Namespace) -> Diagnostics { recurse_statements(&func.body, ns, &mut state); - state.diagnostic.remove_overlapping(); - if pt::FunctionTy::Function == func.ty && !func.is_accessor { if state.required_access == Access::None { match func.mutability { @@ -349,6 +347,7 @@ fn read_expression(expr: &Expression, state: &mut StateCheck) -> bool { Expression::Assign { left, right, .. } => { right.recurse(state, read_expression); left.recurse(state, write_expression); + return false; } Expression::StorageArrayLength { loc, .. } => { state.data_account |= DataAccountUsage::READ; diff --git a/src/sema/statements.rs b/src/sema/statements.rs index c24e0f7595..8378ec90db 100644 --- a/src/sema/statements.rs +++ b/src/sema/statements.rs @@ -2001,7 +2001,7 @@ fn return_with_values( diagnostics, ResolveTo::Type(&return_ty), )?; - let expr = expr.cast(loc, &return_ty, true, ns, diagnostics)?; + let expr = expr.cast(&expr_return.loc(), &return_ty, true, ns, diagnostics)?; used_variable(ns, &expr, symtable); exprs.push(expr); } diff --git a/tests/contract_testcases/evm/builtins/address_code_01.sol b/tests/contract_testcases/evm/builtins/address_code_01.sol index 81808d5d07..aba2467e85 100644 --- a/tests/contract_testcases/evm/builtins/address_code_01.sol +++ b/tests/contract_testcases/evm/builtins/address_code_01.sol @@ -7,4 +7,4 @@ contract UpgradeableProxy { } // ---- Expect: diagnostics ---- -// error: 5:9-38: conversion from bytes to uint256 not possible +// error: 5:16-38: conversion from bytes to uint256 not possible diff --git a/tests/contract_testcases/polkadot/enums/test_cast_errors.sol b/tests/contract_testcases/polkadot/enums/test_cast_errors.sol index 4b013856bd..692b304bdd 100644 --- a/tests/contract_testcases/polkadot/enums/test_cast_errors.sol +++ b/tests/contract_testcases/polkadot/enums/test_cast_errors.sol @@ -5,4 +5,4 @@ contract test { } } // ---- Expect: diagnostics ---- -// error: 4:17-33: implicit conversion from enum test.state to uint8 not allowed +// error: 4:24-33: implicit conversion from enum test.state to uint8 not allowed diff --git a/tests/contract_testcases/polkadot/functions/global_functions_07.sol b/tests/contract_testcases/polkadot/functions/global_functions_07.sol index 88aa6ab26b..3d2eeb769b 100644 --- a/tests/contract_testcases/polkadot/functions/global_functions_07.sol +++ b/tests/contract_testcases/polkadot/functions/global_functions_07.sol @@ -4,4 +4,4 @@ // ---- Expect: diagnostics ---- // warning: 2:34-35: declaration of 'x' shadows function // note 2:18-19: previous declaration of function -// error: 2:58-69: function declared 'pure' but this expression reads from state +// error: 2:65-69: function declared 'pure' but this expression reads from state diff --git a/tests/contract_testcases/polkadot/functions/mutability_02.sol b/tests/contract_testcases/polkadot/functions/mutability_02.sol index ef0436ee5d..364ed07c42 100644 --- a/tests/contract_testcases/polkadot/functions/mutability_02.sol +++ b/tests/contract_testcases/polkadot/functions/mutability_02.sol @@ -4,4 +4,4 @@ abstract contract test { } } // ---- Expect: diagnostics ---- -// error: 3:17-30: function declared 'pure' but this expression reads from state +// error: 3:24-30: function declared 'pure' but this expression reads from state diff --git a/tests/contract_testcases/polkadot/value/this_address_01.sol b/tests/contract_testcases/polkadot/value/this_address_01.sol index 265fca13f0..fc28654c1e 100644 --- a/tests/contract_testcases/polkadot/value/this_address_01.sol +++ b/tests/contract_testcases/polkadot/value/this_address_01.sol @@ -5,4 +5,4 @@ } } // ---- Expect: diagnostics ---- -// error: 4:17-28: implicit conversion to address from contract b not allowed +// error: 4:24-28: implicit conversion to address from contract b not allowed diff --git a/tests/contract_testcases/solana/negative_exponent.sol b/tests/contract_testcases/solana/negative_exponent.sol index a4249efd78..e5a2ee8a68 100644 --- a/tests/contract_testcases/solana/negative_exponent.sol +++ b/tests/contract_testcases/solana/negative_exponent.sol @@ -12,4 +12,4 @@ contract c { // ---- Expect: diagnostics ---- // warning: 6:16-26: ethereum currency unit used while targeting Solana -// error: 9:2-20: conversion to uint256 from rational not allowed +// error: 9:9-20: conversion to uint256 from rational not allowed