CLI error handling
All checks were successful
CI/CD Pipeline / test (pull_request) Successful in 37s
CI/CD Pipeline / build (pull_request) Has been skipped
CI/CD Pipeline / release (pull_request) Has been skipped

This commit is contained in:
2026-01-02 16:44:38 -07:00
parent 4c704b8960
commit 2070c2e4ca
4 changed files with 35 additions and 5 deletions

View File

@@ -1589,7 +1589,7 @@ impl<'a> Parser<'a> {
} else {
// we need to rewind our tokenizer to our previous location
self.tokenizer.seek(SeekFrom::Current(
self.tokenizer.loc() - current_token_index,
current_token_index - self.tokenizer.loc(),
))?;
let syscall = self.spanned(|p| p.syscall())?;

View File

@@ -149,6 +149,23 @@ fn test_const_hash_expression() -> Result<()> {
Ok(())
}
#[test]
fn test_const_hash() -> Result<()> {
// This test explicitly validates the tokenizer rewind logic.
// When parsing "const h = hash(...)", the parser:
// 1. Consumes "const", identifier, "="
// 2. Attempts to parse "hash(...)" as a literal - this fails
// 3. Must rewind the tokenizer to before "hash"
// 4. Then parse it as a syscall
// If the rewind offset is wrong (e.g., positive instead of negative),
// the tokenizer will be at the wrong position and parsing will fail.
let expr = parser!(r#"const h = hash("ComponentComputer")"#)
.parse()?
.unwrap();
assert_eq!(r#"(const h = hash("ComponentComputer"))"#, expr.to_string());
Ok(())
}
#[test]
fn test_negative_literal_const() -> Result<()> {
let expr = parser!(r#"const i = -123"#).parse()?.unwrap();