Skip to content

Commit

Permalink
Not needed
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed Oct 17, 2023
1 parent 10bb7b4 commit f42cc59
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 70 deletions.
61 changes: 0 additions & 61 deletions src/sema/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, usize>;

// in data val is the diagnostic index
let data: Vec<Iv> = 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(
Expand Down
3 changes: 1 addition & 2 deletions src/sema/mutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sema/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/contract_testcases/evm/builtins/address_code_01.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/contract_testcases/solana/negative_exponent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f42cc59

Please sign in to comment.