Include the target of bad redirects in the error (#9947)

Fixes #8877
This commit is contained in:
99jte 2023-08-13 05:01:32 -07:00 committed by GitHub
parent b2ff4d6bc0
commit 5b136d450f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -3192,6 +3192,15 @@ impl<'s> Populator<'s> {
}
}
}
ParseTokenType::redirection if self.peek_type(0) == ParseTokenType::string => {
let next = self.tokens.pop();
parse_error_range!(
self,
next.range().combine(tok.range()),
ParseErrorCode::generic,
"Expected a string, but found a redirection"
);
}
ParseTokenType::pipe
| ParseTokenType::redirection
| ParseTokenType::background

View File

@ -237,6 +237,18 @@ impl SourceRange {
.try_into()
.unwrap()
}
pub fn combine(&self, other: Self) -> Self {
let start = std::cmp::min(self.start, other.start);
SourceRange {
start,
length: std::cmp::max(self.end(), other.end())
.checked_sub(start.try_into().unwrap())
.expect("Overflow")
.try_into()
.unwrap(),
}
}
fn end_ffi(&self) -> u32 {
self.start.checked_add(self.length).expect("Overflow")
}

View File

@ -4883,6 +4883,11 @@ static void test_highlighting() {
});
#endif
highlight_tests.push_back({
{L">", highlight_role_t::error},
{L"echo", highlight_role_t::error},
});
bool saved_flag = feature_test(feature_flag_t::ampersand_nobg_in_token);
feature_set(feature_flag_t::ampersand_nobg_in_token, true);
for (const highlight_component_list_t &components : highlight_tests) {