Skip to content

Commit

Permalink
fix(diagnostics): add 'set_semantic_meaning' to the side effects list
Browse files Browse the repository at this point in the history
  • Loading branch information
pront committed Nov 27, 2024
1 parent 7a4d7fe commit 32231db
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/compiler/unused_expression_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ use crate::parser::{Literal, Program, Span};
use std::collections::{BTreeMap, HashMap};
use tracing::warn;

const SIDE_EFFECT_FUNCTIONS: [&str; 5] =
["del", "log", "assert", "assert_eq", "set_semantic_meaning"];

#[must_use]
pub fn check_for_unused_results(ast: &Program) -> DiagnosticList {
let expression_visitor = AstVisitor { ast };
Expand Down Expand Up @@ -351,23 +354,19 @@ impl AstVisitor<'_> {
state.mark_level_as_expecting_result();
}

match function_call.ident.0.as_str() {
// All bets are off for functions with side-effects.
"del" | "log" | "assert" | "assert_eq" => (),
_ => {
if let Some(closure) = &function_call.closure {
for variable in &closure.variables {
state.mark_identifier_pending_usage(&variable.node, &variable.span);
}
state.mark_level_as_expecting_result();
self.visit_block(&closure.block, state);
state.mark_level_as_not_expecting_result();
} else if state.is_unused() {
state.append_diagnostic(
format!("unused result for function call `{function_call}`"),
span,
);
if !SIDE_EFFECT_FUNCTIONS.contains(&function_call.ident.0.as_str()) {
if let Some(closure) = &function_call.closure {
for variable in &closure.variables {
state.mark_identifier_pending_usage(&variable.node, &variable.span);
}
state.mark_level_as_expecting_result();
self.visit_block(&closure.block, state);
state.mark_level_as_not_expecting_result();
} else if state.is_unused() {
state.append_diagnostic(
format!("unused result for function call `{function_call}`"),
span,
);
}
}

Expand Down

0 comments on commit 32231db

Please sign in to comment.