Skip to main content

forge_lint/sol/low/
msg_value_loop.rs

1use super::{MsgValueLoop, payable_loop::for_each_payable_loop_expr};
2use crate::{
3    linter::{LateLintPass, LintContext},
4    sol::{Severity, SolLint},
5};
6use solar::sema::{Gcx, builtins::Builtin, hir::Function};
7
8declare_forge_lint!(
9    MSG_VALUE_LOOP,
10    Severity::Low,
11    "msg-value-loop",
12    "payable function uses `msg.value` inside a loop"
13);
14
15impl<'gcx> LateLintPass<'gcx> for MsgValueLoop {
16    fn check_function(&mut self, ctx: &LintContext, gcx: Gcx<'gcx>, func: &'gcx Function<'gcx>) {
17        for_each_payable_loop_expr(gcx, func, |expr| {
18            if gcx.resolved_builtin(expr) == Some(Builtin::MsgValue) {
19                ctx.emit(&MSG_VALUE_LOOP, expr.span);
20            }
21        });
22    }
23}