From 454cde0b659b07b3bd5bb6cb04f665a3f124240f Mon Sep 17 00:00:00 2001 From: Matthew Paras <34500476+mattwparas@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:19:03 -0800 Subject: [PATCH] Fix panic during analysis in LSP (#294) --- .../src/compiler/passes/analysis.rs | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/steel-core/src/compiler/passes/analysis.rs b/crates/steel-core/src/compiler/passes/analysis.rs index 1df250140..292086130 100644 --- a/crates/steel-core/src/compiler/passes/analysis.rs +++ b/crates/steel-core/src/compiler/passes/analysis.rs @@ -3461,29 +3461,31 @@ impl<'a> VisitorMutRefUnit for FlattenAnonymousFunctionCalls<'a> { .map(|x| x.atom_syntax_object().unwrap().syntax_object_id) .collect::>(); - let all_dont_contain_references = inner_l.args[1..] - .iter() - .all(|x| !ExprContainsIds::contains(self.analysis, &arg_ids, x)); + if !inner_l.is_empty() { + let all_dont_contain_references = inner_l.args[1..] + .iter() + .all(|x| !ExprContainsIds::contains(self.analysis, &arg_ids, x)); - if all_dont_contain_references { - if let Some(function_b) = inner_l.first_func_mut() { - // Then we should be able to flatten the function into one + if all_dont_contain_references { + if let Some(function_b) = inner_l.first_func_mut() { + // Then we should be able to flatten the function into one - // TODO: Check that any of the vars we're using are used in the body expression - // They can only be used in the argument position + // TODO: Check that any of the vars we're using are used in the body expression + // They can only be used in the argument position - let mut dummy = ExprKind::empty(); + let mut dummy = ExprKind::empty(); - // Extract the inner body - std::mem::swap(&mut function_b.body, &mut dummy); + // Extract the inner body + std::mem::swap(&mut function_b.body, &mut dummy); - inner_body = Some(dummy); + inner_body = Some(dummy); - // TODO: This doesn't work quite yet - - function_a.args.append(&mut function_b.args); - args.extend(inner_l.args.drain(1..)); + // TODO: This doesn't work quite yet - + function_a.args.append(&mut function_b.args); + args.extend(inner_l.args.drain(1..)); - changed = true; + changed = true; + } } } }