Skip to content

Commit

Permalink
Analyze - Skip SAA1 suggestion if consts used in isNil check (#694)
Browse files Browse the repository at this point in the history
Co-authored-by: Brett Mayson <[email protected]>
  • Loading branch information
PabstMirror and BrettMayson authored May 15, 2024
1 parent bd2a5cf commit 2d26cf6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libs/sqf/src/analyze/if_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ pub fn if_assign(statements: &Statements, processed: &Processed) -> Vec<Arc<dyn

fn check_expression(expression: &Expression, processed: &Processed) -> Vec<Arc<dyn Code>> {
if let Expression::BinaryCommand(BinaryCommand::Named(name), if_cmd, code, _) = expression {
if name == "then" {
if name.to_lowercase() == "then" {
let Expression::UnaryCommand(UnaryCommand::Named(_), condition, _) = &**if_cmd else {
return Vec::new();
};
if let Expression::BinaryCommand(BinaryCommand::Else, lhs_expr, rhs_expr, _) = &**code {
let lhs = extract_constant(lhs_expr);
let rhs = extract_constant(rhs_expr);
if let (Some(lhs), Some(rhs)) = (lhs, rhs) {
// Skip if consts are used in a isNil check (e.g. [x, 5] select (isNil "x") will error in scheduled)
if let Expression::UnaryCommand(UnaryCommand::Named(name), _, _) = &**condition
{
if name.to_lowercase() == "isnil" {
return Vec::new();
}
}
return vec![Arc::new(IfAssign::new(
if_cmd.span(),
(condition.source(), condition.full_span()),
Expand Down

0 comments on commit 2d26cf6

Please sign in to comment.