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
…#1148)

* fix(diagnostics): add 'set_semantic_meaning' to the side effects list

* changelog
  • Loading branch information
pront authored Nov 27, 2024
1 parent 7a4d7fe commit d14bcb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.d/1148.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed false warning when using `set_semantic_meaning`.
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 d14bcb8

Please sign in to comment.