* Fix bug #2921

Moving whether a range should be parsed further back, giving e.G. parsing of
invocations precedence fixes the bug

* Add test
This commit is contained in:
Leonhard Kipp 2021-01-20 19:58:37 +01:00 committed by GitHub
parent 05e42381df
commit fec50d8cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,13 @@
use nu_test_support::nu;
#[test]
fn test_parse_invocation_with_range() {
let actual = nu!(
cwd: ".",
r#"
let foo = 3
echo $(echo 1..$foo | each { echo $it }) | to json
"#
);
assert_eq!(actual.out, "[1,2,3]")
}

View File

@ -1 +1,2 @@
mod invocation;
mod operator; mod operator;

View File

@ -446,6 +446,8 @@ fn parse_dollar_expr(
//Return invocation //Return invocation
trace!("Parsing invocation expression"); trace!("Parsing invocation expression");
parse_invocation(lite_arg, scope) parse_invocation(lite_arg, scope)
} else if lite_arg.item.contains("..") {
parse_range(lite_arg, scope)
} else if lite_arg.item.contains('.') { } else if lite_arg.item.contains('.') {
trace!("Parsing path expression"); trace!("Parsing path expression");
parse_full_column_path(lite_arg, scope) parse_full_column_path(lite_arg, scope)
@ -742,7 +744,7 @@ fn parse_arg(
scope: &dyn ParserScope, scope: &dyn ParserScope,
lite_arg: &Spanned<String>, lite_arg: &Spanned<String>,
) -> (SpannedExpression, Option<ParseError>) { ) -> (SpannedExpression, Option<ParseError>) {
if lite_arg.item.starts_with('$') && parse_range(lite_arg, scope).1.is_some() { if lite_arg.item.starts_with('$') {
return parse_dollar_expr(&lite_arg, scope); return parse_dollar_expr(&lite_arg, scope);
} }