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:
JT 2023-07-27 06:22:08 +12:00 committed by GitHub
parent 88a890c11f
commit f8d325dbfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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, .. }) => {

View File

@ -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",
)
}