Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Dec 12, 2023
1 parent 2be8e1a commit 3f99f81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
9 changes: 3 additions & 6 deletions src/codegen/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,12 +1156,9 @@ pub fn expression(
ty,
}
}
// Stray type operator which is unused, can return anything here
ast::Expression::TypeOperator { loc, .. } => Expression::BoolLiteral {
loc: *loc,
value: false,
},
ast::Expression::List { .. } => unreachable!("List shall not appear in the CFG"),
ast::Expression::TypeOperator { .. } | ast::Expression::List { .. } => {
unreachable!("List shall not appear in the CFG")
}
}
}

Expand Down
61 changes: 34 additions & 27 deletions src/codegen/statements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,37 +170,44 @@ pub(crate) fn statement(
}
}
Statement::Expression(_, _, expr) => {
if let ast::Expression::Assign { left, right, .. } = &expr {
if should_remove_assignment(left, func, opt, ns) {
let mut params = SideEffectsCheckParameters {
cfg,
contract_no,
func: Some(func),
ns,
vartab,
opt,
};
right.recurse(&mut params, process_side_effects_expressions);

return;
match expr {
ast::Expression::Assign { left, right, .. } => {
if should_remove_assignment(left, func, opt, ns) {
let mut params = SideEffectsCheckParameters {
cfg,
contract_no,
func: Some(func),
ns,
vartab,
opt,
};
right.recurse(&mut params, process_side_effects_expressions);

return;
}
}
} else if let ast::Expression::Builtin { args, .. } = expr {
// When array pop and push are top-level expressions, they can be removed
if should_remove_assignment(expr, func, opt, ns) {
let mut params = SideEffectsCheckParameters {
cfg,
contract_no,
func: Some(func),
ns,
vartab,
opt,
};
for arg in args {
arg.recurse(&mut params, process_side_effects_expressions);
ast::Expression::Builtin { args, .. } => {
// When array pop and push are top-level expressions, they can be removed
if should_remove_assignment(expr, func, opt, ns) {
let mut params = SideEffectsCheckParameters {
cfg,
contract_no,
func: Some(func),
ns,
vartab,
opt,
};
for arg in args {
arg.recurse(&mut params, process_side_effects_expressions);
}

return;
}

}
ast::Expression::TypeOperator { .. } => {
return;
}
_ => (),
}

let _ = expression(expr, cfg, contract_no, Some(func), ns, vartab, opt);
Expand Down
6 changes: 6 additions & 0 deletions tests/polkadot_tests/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ fn weekdays() {
x = Weekday(2);
assert(x == Weekday.Wednesday);
assert(type(Weekday).max == 6);
assert(type(Weekday).min == 0);
// stray type() does not do anything.
type(Weekday);
}
}",
);
Expand Down

0 comments on commit 3f99f81

Please sign in to comment.