From f5b8ae61cc0bdc0f384b0621872dd24531a57642 Mon Sep 17 00:00:00 2001 From: 132ikl <132@ikl.sh> Date: Wed, 26 Feb 2025 22:39:19 -0500 Subject: [PATCH] Only report warning for closures, not any block --- crates/nu-cmd-lang/src/parse_const_test.rs | 10 ++++-- crates/nu-parser/src/parse_keywords.rs | 8 +++-- crates/nu-parser/src/parser.rs | 36 ++++++++++++++++++---- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/crates/nu-cmd-lang/src/parse_const_test.rs b/crates/nu-cmd-lang/src/parse_const_test.rs index 7870b37648..92b2198b24 100644 --- a/crates/nu-cmd-lang/src/parse_const_test.rs +++ b/crates/nu-cmd-lang/src/parse_const_test.rs @@ -11,8 +11,14 @@ fn quickcheck_parse(data: String) -> bool { let mut working_set = StateWorkingSet::new(&context); let _ = working_set.add_file("quickcheck".into(), data.as_bytes()); - let _ = - nu_parser::parse_block(&mut working_set, &tokens, Span::new(0, 0), false, false); + let _ = nu_parser::parse_block( + &mut working_set, + &tokens, + Span::new(0, 0), + false, + false, + false, + ); } } true diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 31dfbb6ea3..9fe06aaa54 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -3339,7 +3339,8 @@ pub fn parse_let(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline } let rvalue_span = Span::concat(&spans[(span.0 + 1)..]); - let rvalue_block = parse_block(working_set, &tokens, rvalue_span, false, true); + let rvalue_block = + parse_block(working_set, &tokens, rvalue_span, false, true, false); let output_type = rvalue_block.output_type(); @@ -3459,7 +3460,7 @@ pub fn parse_const(working_set: &mut StateWorkingSet, spans: &[Span]) -> (Pipeli trace!("parsing: const right-hand side subexpression"); let rvalue_block = - parse_block(working_set, &rvalue_tokens, rvalue_span, false, true); + parse_block(working_set, &rvalue_tokens, rvalue_span, false, true, false); let rvalue_ty = rvalue_block.output_type(); let rvalue_block_id = working_set.add_block(Arc::new(rvalue_block)); let rvalue = Expression::new( @@ -3621,7 +3622,8 @@ pub fn parse_mut(working_set: &mut StateWorkingSet, spans: &[Span]) -> Pipeline } let rvalue_span = Span::concat(&spans[(span.0 + 1)..]); - let rvalue_block = parse_block(working_set, &tokens, rvalue_span, false, true); + let rvalue_block = + parse_block(working_set, &tokens, rvalue_span, false, true, false); let output_type = rvalue_block.output_type(); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 8367e4c9a4..f1df558de1 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -2452,7 +2452,7 @@ pub fn parse_full_cell_path( // Creating a Type scope to parse the new block. This will keep track of // the previous input type found in that block - let output = parse_block(working_set, &output, span, true, true); + let output = parse_block(working_set, &output, span, true, true, false); let ty = output.output_type(); @@ -4596,7 +4596,14 @@ pub fn parse_block_expression(working_set: &mut StateWorkingSet, span: Span) -> _ => (None, 0), }; - let mut output = parse_block(working_set, &output[amt_to_skip..], span, false, false); + let mut output = parse_block( + working_set, + &output[amt_to_skip..], + span, + false, + false, + false, + ); if let Some(signature) = signature { output.signature = signature.0; @@ -4919,7 +4926,14 @@ pub fn parse_closure_expression( } } - let mut output = parse_block(working_set, &output[amt_to_skip..], span, false, false); + let mut output = parse_block( + working_set, + &output[amt_to_skip..], + span, + false, + false, + true, + ); if let Some(signature) = signature { output.signature = signature.0; @@ -5217,7 +5231,7 @@ pub fn parse_assignment_expression( working_set.parse_errors.extend(rhs_error); trace!("parsing: assignment right-hand side subexpression"); - let rhs_block = parse_block(working_set, &rhs_tokens, rhs_span, false, true); + let rhs_block = parse_block(working_set, &rhs_tokens, rhs_span, false, true, false); let rhs_ty = rhs_block.output_type(); // TEMP: double-check that if the RHS block starts with an external call, it must start with a @@ -6293,6 +6307,7 @@ pub fn parse_block( span: Span, scoped: bool, is_subexpression: bool, + is_closure: bool, ) -> Block { let (lite_block, err) = lite_parse(tokens, working_set); if let Some(err) = err { @@ -6330,7 +6345,9 @@ pub fn parse_block( .flat_map(|pipeline| pipeline.elements.first()) .any(|element| element.has_in_variable(working_set)) { - check_block_pipes_in(working_set, &block); + if is_closure { + check_block_pipes_in(working_set, &block); + } // Move the block out to prepare it to become a subexpression let inner_block = std::mem::take(&mut block); @@ -6912,7 +6929,14 @@ pub fn parse( working_set.error(err) } - Arc::new(parse_block(working_set, &output, new_span, scoped, false)) + Arc::new(parse_block( + working_set, + &output, + new_span, + scoped, + false, + false, + )) } };