mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 14:51:15 +00:00
Fix panic when parsing wrong import statement
Have to be several tests because the parser bails out at the first error. The error message is not optimal but better than a panic
This commit is contained in:
parent
49868a8dae
commit
1e730eb845
5 changed files with 65 additions and 4 deletions
|
@ -0,0 +1,13 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
import;
|
||||
// ^error{Syntax error: expected LBrace}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
import foo from bar;
|
||||
// ^error{Syntax error: expected LBrace}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
import { A } yo;
|
||||
// ^error{Expected from keyword for import statement}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* LICENSE BEGIN
|
||||
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
||||
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
||||
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
This file is also available under commercial licensing terms.
|
||||
Please contact info@sixtyfps.io for more information.
|
||||
LICENSE END */
|
||||
|
||||
import { } from yo;
|
||||
// ^error{Expected plain string literal}
|
||||
|
|
@ -297,10 +297,15 @@ impl<'a> TypeLoader<'a> {
|
|||
// If there was error (esp parse error) we don't want to report further error in this document.
|
||||
// because they might be nonsense (TODO: we should check that the parse error were really in this document).
|
||||
// But we still want to create a document to give better error messages in the root document.
|
||||
let mut ignore_diag = BuildDiagnostics::default();
|
||||
ignore_diag.push_error_with_span(
|
||||
"Dummy error because some of the code asserts there there was an error".into(),
|
||||
Default::default(),
|
||||
);
|
||||
let doc = crate::object_tree::Document::from_node(
|
||||
dependency_doc,
|
||||
foreign_imports,
|
||||
&mut BuildDiagnostics::default(), // New diagnostics that we will ignore
|
||||
&mut ignore_diag,
|
||||
&dependency_registry,
|
||||
);
|
||||
self.all_documents.docs.insert(path.to_owned(), doc);
|
||||
|
@ -406,9 +411,13 @@ impl<'a> TypeLoader<'a> {
|
|||
let mut dependencies = DependenciesByFile::new();
|
||||
|
||||
for import in doc.ImportSpecifier() {
|
||||
let import_uri = import.child_token(SyntaxKind::StringLiteral).expect(
|
||||
"Internal error: missing import uri literal, this is a parsing/grammar bug",
|
||||
);
|
||||
let import_uri = match import.child_token(SyntaxKind::StringLiteral) {
|
||||
Some(import_uri) => import_uri,
|
||||
None => {
|
||||
debug_assert!(doc_diagnostics.has_error());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let path_to_import = import_uri.text().to_string();
|
||||
let path_to_import = path_to_import.trim_matches('\"').to_string();
|
||||
if path_to_import.is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue