Forbid reserved variable names for function arguments (#11169)

Works for all arguments and flags. Because the signature parsing doesn't
give the spans, it is flags the entire signature.

Also added a constant with reserved variable names.

Fix #11158.
This commit is contained in:
Andrej Kolchin
2023-11-29 17:29:07 +00:00
committed by GitHub
parent e290fa0e68
commit 0e1322e6d6
2 changed files with 40 additions and 4 deletions

View File

@ -304,6 +304,21 @@ fn parse_function_signature(#[case] phrase: &str) {
assert!(actual.err.is_empty());
}
#[rstest]
#[case("def test [ in ] {}")]
#[case("def test [ in: string ] {}")]
#[case("def test [ nu: int ] {}")]
#[case("def test [ env: record<> ] {}")]
#[case("def test [ --env ] {}")]
#[case("def test [ --nu: int ] {}")]
#[case("def test [ --in (-i): list<any> ] {}")]
#[case("def test [ a: string, b: int, in: table<a: int b: int> ] {}")]
#[case("def test [ env, in, nu ] {}")]
fn parse_function_signature_name_is_builtin_var(#[case] phrase: &str) {
let actual = nu!(phrase);
assert!(actual.err.contains("nu::parser::name_is_builtin_var"))
}
#[rstest]
#[case("let a: int = 1")]
#[case("let a: string = 'qwe'")]