Compiler better test coverage in case of error and fix panics

The compile_syntax_node was used by the syntax_test in case of error
to still cover the coverage, but commit e3908cfce6
made this function a noop when there is an error already.

The LSP does try to build an object tree even though there are error in
order to have the most information even in that case, so we must ensure
that it doesn't panic left and right.

This commit also fix some of these panics.
This commit is contained in:
Olivier Goffart 2024-06-11 15:37:35 +02:00
parent 47a61dda10
commit 60e7d54e67
3 changed files with 14 additions and 9 deletions

View file

@ -206,10 +206,6 @@ pub async fn compile_syntax_node(
) -> (object_tree::Document, diagnostics::BuildDiagnostics, typeloader::TypeLoader) {
let mut loader = prepare_for_compile(&mut diagnostics, compiler_config);
if diagnostics.has_error() {
return (crate::object_tree::Document::default(), diagnostics, loader);
}
let doc_node: parser::syntax_nodes::Document = doc_node.into();
let type_registry =

View file

@ -1214,12 +1214,10 @@ impl Element {
match token.as_token().unwrap().text() {
"pure" => pure = Some(true),
"public" => {
debug_assert_eq!(visibility, PropertyVisibility::Private);
visibility = PropertyVisibility::Public;
pure = pure.or(Some(false));
}
"protected" => {
debug_assert_eq!(visibility, PropertyVisibility::Private);
visibility = PropertyVisibility::Protected;
pure = pure.or(Some(false));
}

View file

@ -77,10 +77,20 @@ fn resolve_alias(
};
drop(borrow_mut);
let nr = match &elem.borrow().bindings[prop].borrow().expression {
let borrow = elem.borrow();
let Some(binding) = borrow.bindings.get(prop) else {
assert!(diag.has_error());
return;
};
let nr = match &binding.borrow().expression {
Expression::Uncompiled(node) => {
let node = syntax_nodes::TwoWayBinding::new(node.clone())
.expect("The parser only avoid missing types for two way bindings");
let Some(node) = syntax_nodes::TwoWayBinding::new(node.clone()) else {
assert!(
diag.has_error(),
"The parser only avoid missing types for two way bindings"
);
return;
};
let mut lookup_ctx = LookupCtx::empty_context(type_register, diag);
lookup_ctx.property_name = Some(prop);
lookup_ctx.property_type = old_type.clone();
@ -89,6 +99,7 @@ fn resolve_alias(
}
_ => panic!("There should be a Uncompiled expression at this point."),
};
drop(borrow);
let mut ty = Type::Invalid;
if let Some(nr) = &nr {