mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Fix parsing of unfinished import
statement
Fix #6588 Note for the test: parse error at the end of the file are actually reported at offset 0. Use a trick to add more `^` at the beginning to mean that. (Offset 0 is actually offset 1 as the column starts at 1)
This commit is contained in:
parent
4e50fbdb15
commit
6c81d5069e
3 changed files with 15 additions and 6 deletions
|
@ -332,13 +332,12 @@ fn parse_import_identifier_list(p: &mut impl Parser) -> bool {
|
|||
p.consume();
|
||||
return true;
|
||||
}
|
||||
SyntaxKind::Eof => return false,
|
||||
SyntaxKind::Comma => {
|
||||
p.consume();
|
||||
}
|
||||
_ => {
|
||||
p.consume();
|
||||
p.error("Expected comma")
|
||||
p.error("Expected comma or brace");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
internal/compiler/tests/syntax/fuzzing/6588.slint
Normal file
6
internal/compiler/tests/syntax/fuzzing/6588.slint
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
//^^^error{Expected comma or brace}
|
||||
|
||||
import { Bmp
|
||||
|
|
@ -124,10 +124,14 @@ fn process_diagnostics(
|
|||
let offset = loop {
|
||||
line_counter += 1;
|
||||
if line_counter >= lines_to_source {
|
||||
break line_offset;
|
||||
break line_offset + column;
|
||||
}
|
||||
line_offset = source[..line_offset].rfind('\n').unwrap_or(0);
|
||||
} + column;
|
||||
if let Some(o) = source[..line_offset].rfind('\n') {
|
||||
line_offset = o;
|
||||
} else {
|
||||
break 1;
|
||||
};
|
||||
};
|
||||
|
||||
let expected_diag_level = match warning_or_error {
|
||||
"warning" => i_slint_compiler::diagnostics::DiagnosticLevel::Warning,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue