From e50103281dc9231a792c560d1f07c0eb0f46f094 Mon Sep 17 00:00:00 2001 From: youknowdot Date: Wed, 21 Oct 2026 18:17:41 -0700 Subject: [PATCH] Fix single-input multiple-statement diagnostic ranges (#9289) Preserve comment spans and count a logical newline once when converting single-mode multiple-statement diagnostics to character locations. Assisted-by: OpenAI Codex:model-version-unavailable --- crates/compiler/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/compiler/src/lib.rs b/crates/compiler/src/lib.rs index bfad4741b..1c1ecb13e 100644 --- a/crates/compiler/src/lib.rs +++ b/crates/compiler/src/lib.rs @@ -1339,15 +1339,18 @@ pub fn single_mode_multiple_statements_error( let position = match newline_index.checked_sub(1).map(|index| &tokens[index]) { Some(comment) if comment.kind() == TokenKind::Comment => comment.start(), _ => newline.start(), - } - .to_usize(); - Some(CompileError::from_source_error( + }; + // Include the comment and one logical newline character. Using the token's + // full end would count both bytes of CRLF; position + 1 truncates comments. + Some(CompileError::from_ruff_parse_error( + parser::ParseError { + error: parser::ParseErrorType::OtherError( + "multiple statements found while compiling a single statement".to_owned(), + ), + location: ruff_text_size::TextRange::new(position, newline.start() + TextSize::new(1)), + }, source_file, - CpythonDiagnostic::new( - "multiple statements found while compiling a single statement".to_owned(), - position, - position, - ), + Mode::Single, )) }