Fix wrong parsing of signatures in predecl scan (#10637)

This commit is contained in:
Jakub Žádník 2023-10-07 16:42:09 +03:00 committed by GitHub
parent eb4fd144eb
commit 67b5e1bde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -31,7 +31,7 @@ use crate::{
lite_parser::{lite_parse, LiteCommand, LiteElement},
parser::{
check_call, check_name, garbage, garbage_pipeline, parse, parse_call, parse_expression,
parse_import_pattern, parse_internal_call, parse_multispan_value, parse_signature,
parse_full_signature, parse_import_pattern, parse_internal_call, parse_multispan_value,
parse_string, parse_value, parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
},
unescape_unquote_string, Token, TokenContents,
@ -228,7 +228,7 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) {
// The second time is when we actually parse the body itworking_set.
// We can't reuse the first time because the variables that are created during parse_signature
// are lost when we exit the scope below.
let sig = parse_signature(working_set, spans[signature_pos]);
let sig = parse_full_signature(working_set, &spans[signature_pos..]);
working_set.parse_errors.truncate(starting_error_count);
working_set.exit_scope();

View File

@ -102,6 +102,23 @@ fn parse_file_relative_to_parsed_file_simple() {
})
}
#[test]
fn predecl_signature_parse() {
Playground::setup("predecl_signature_parse", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"spam.nu",
"
def main [] { foo }
def foo []: nothing -> nothing { print 'foo' }
",
)]);
let actual = nu!(cwd: dirs.test(), pipeline("nu spam.nu"));
assert_eq!(actual.out, "foo");
})
}
#[ignore]
#[test]
fn parse_file_relative_to_parsed_file() {