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 e37a8c8
Show file tree
Hide file tree
Showing 4 changed files with 46 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")

Check warning on line 1160 in src/codegen/expression.rs

View check run for this annotation

Codecov / codecov/patch

src/codegen/expression.rs#L1160

Added line #L1160 was not covered by tests
}
}
}

Expand Down
62 changes: 35 additions & 27 deletions src/codegen/statements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,37 +170,45 @@ 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 { .. } => {
// just a stray type(int), no code to generate
return;
}
_ => (),
}

let _ = expression(expr, cfg, contract_no, Some(func), ns, vartab, opt);
Expand Down
2 changes: 2 additions & 0 deletions src/sema/external_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ fn check_statement(stmt: &Statement, call_list: &mut CallList) -> bool {
cond.recurse(call_list, check_expression);
}
Statement::Expression(_, _, expr) => {
// if expression is a singular Expression::InternalFunction, then does nothing
// and it's never called.
if !matches!(expr, Expression::InternalFunction { .. }) {
expr.recurse(call_list, check_expression);
}
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 e37a8c8

Please sign in to comment.