Only report warning for closures, not any block

This commit is contained in:
132ikl 2025-02-26 22:39:19 -05:00
parent c292b5f609
commit f5b8ae61cc
3 changed files with 43 additions and 11 deletions

View File

@ -11,8 +11,14 @@ fn quickcheck_parse(data: String) -> bool {
let mut working_set = StateWorkingSet::new(&context); let mut working_set = StateWorkingSet::new(&context);
let _ = working_set.add_file("quickcheck".into(), data.as_bytes()); let _ = working_set.add_file("quickcheck".into(), data.as_bytes());
let _ = let _ = nu_parser::parse_block(
nu_parser::parse_block(&mut working_set, &tokens, Span::new(0, 0), false, false); &mut working_set,
&tokens,
Span::new(0, 0),
false,
false,
false,
);
} }
} }
true true

View File

@ -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_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(); 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"); trace!("parsing: const right-hand side subexpression");
let rvalue_block = 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_ty = rvalue_block.output_type();
let rvalue_block_id = working_set.add_block(Arc::new(rvalue_block)); let rvalue_block_id = working_set.add_block(Arc::new(rvalue_block));
let rvalue = Expression::new( 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_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(); let output_type = rvalue_block.output_type();

View File

@ -2452,7 +2452,7 @@ pub fn parse_full_cell_path(
// Creating a Type scope to parse the new block. This will keep track of // Creating a Type scope to parse the new block. This will keep track of
// the previous input type found in that block // 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(); let ty = output.output_type();
@ -4596,7 +4596,14 @@ pub fn parse_block_expression(working_set: &mut StateWorkingSet, span: Span) ->
_ => (None, 0), _ => (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 { if let Some(signature) = signature {
output.signature = signature.0; 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 { if let Some(signature) = signature {
output.signature = signature.0; output.signature = signature.0;
@ -5217,7 +5231,7 @@ pub fn parse_assignment_expression(
working_set.parse_errors.extend(rhs_error); working_set.parse_errors.extend(rhs_error);
trace!("parsing: assignment right-hand side subexpression"); 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(); 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 // 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, span: Span,
scoped: bool, scoped: bool,
is_subexpression: bool, is_subexpression: bool,
is_closure: bool,
) -> Block { ) -> Block {
let (lite_block, err) = lite_parse(tokens, working_set); let (lite_block, err) = lite_parse(tokens, working_set);
if let Some(err) = err { if let Some(err) = err {
@ -6330,7 +6345,9 @@ pub fn parse_block(
.flat_map(|pipeline| pipeline.elements.first()) .flat_map(|pipeline| pipeline.elements.first())
.any(|element| element.has_in_variable(working_set)) .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 // Move the block out to prepare it to become a subexpression
let inner_block = std::mem::take(&mut block); let inner_block = std::mem::take(&mut block);
@ -6912,7 +6929,14 @@ pub fn parse(
working_set.error(err) 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,
))
} }
}; };