From 32231dbcae9a36e073f67528da10d2a3c3ac51d5 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Wed, 27 Nov 2024 13:44:54 -0500 Subject: [PATCH 1/2] fix(diagnostics): add 'set_semantic_meaning' to the side effects list --- src/compiler/unused_expression_checker.rs | 31 +++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/compiler/unused_expression_checker.rs b/src/compiler/unused_expression_checker.rs index e0c070f4d3..01157b2052 100644 --- a/src/compiler/unused_expression_checker.rs +++ b/src/compiler/unused_expression_checker.rs @@ -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 }; @@ -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, + ); } } From 135a0da428b6cc4bcbcd7481ab171cf3f4580f9a Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Wed, 27 Nov 2024 13:49:36 -0500 Subject: [PATCH 2/2] changelog --- changelog.d/1148.fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1148.fix.md diff --git a/changelog.d/1148.fix.md b/changelog.d/1148.fix.md new file mode 100644 index 0000000000..000ec08247 --- /dev/null +++ b/changelog.d/1148.fix.md @@ -0,0 +1 @@ +Removed false warning when using `set_semantic_meaning`.