diff --git a/cli/src/tests/parser_test.rs b/cli/src/tests/parser_test.rs index 0fde31a5..a1f730d8 100644 --- a/cli/src/tests/parser_test.rs +++ b/cli/src/tests/parser_test.rs @@ -1004,6 +1004,31 @@ fn test_parsing_with_timeout_during_balancing() { assert!(tree.is_none()); assert!(in_balancing); + // This should not cause an assertion failure. + parser.reset(); + let tree = parser.parse_with_options( + &mut |offset, _| { + if offset >= code.len() { + &[] + } else { + &code.as_bytes()[offset..] + } + }, + None, + Some(ParseOptions::new().progress_callback(&mut |state| { + if state.current_byte_offset() != current_byte_offset { + current_byte_offset = state.current_byte_offset(); + false + } else { + in_balancing = true; + true + } + })), + ); + + assert!(tree.is_none()); + assert!(in_balancing); + // If we resume parsing (implying we didn't call `parser.reset()`), we should be able to // finish parsing the tree, continuing from where we left off. let tree = parser diff --git a/lib/src/parser.c b/lib/src/parser.c index 41a349d4..7aac259e 100644 --- a/lib/src/parser.c +++ b/lib/src/parser.c @@ -2080,6 +2080,7 @@ void ts_parser_reset(TSParser *self) { self->accept_count = 0; self->has_scanner_error = false; self->has_error = false; + self->canceled_balancing = false; self->parse_options = (TSParseOptions) {0}; self->parse_state = (TSParseState) {0}; }