mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Set the rest variable to the correct type (#9816)
# Description This fixes the type of `$rest` to be a `List<...>` so that it properly is checked in function bodies. fixes https://github.com/nushell/nushell/issues/9809
This commit is contained in:
parent
88a890c11f
commit
f8d325dbfe
@ -3695,7 +3695,7 @@ pub fn parse_signature_helper(working_set: &mut StateWorkingSet, span: Span) ->
|
||||
Arg::RestPositional(PositionalArg {
|
||||
shape, var_id, ..
|
||||
}) => {
|
||||
working_set.set_variable_type(var_id.expect("internal error: all custom parameters must have var_ids"), syntax_shape.to_type());
|
||||
working_set.set_variable_type(var_id.expect("internal error: all custom parameters must have var_ids"), Type::List(Box::new(syntax_shape.to_type())));
|
||||
*shape = syntax_shape;
|
||||
}
|
||||
Arg::Flag(Flag { arg, var_id, .. }) => {
|
||||
|
@ -665,3 +665,11 @@ fn properly_nest_captures() -> TestResult {
|
||||
fn properly_nest_captures_call_first() -> TestResult {
|
||||
run_test(r#"do { let b = 3; c; def c [] { $b }; c }"#, "3")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn properly_typecheck_rest_param() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [...rest: string] { $rest | length }; foo "a" "b" "c""#,
|
||||
"3",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user