Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading