Fix panic with invalid code

Fix #6518
This commit is contained in:
Olivier Goffart 2024-10-15 11:15:41 +02:00
parent 4718d5b050
commit f0e02a3aa3
2 changed files with 36 additions and 19 deletions

View file

@ -70,28 +70,31 @@ fn ensure_pure(
}
None => {
if recursion_test.insert(nr.clone()) {
if !ensure_pure(
&nr.element()
.borrow()
.bindings
.get(nr.name())
.expect("private function must be local and defined")
.borrow()
.expression,
None,
level,
recursion_test,
) {
if let Some(diag) = diag.as_deref_mut() {
diag.push_diagnostic(
format!("Call of impure function '{}'", nr.name()),
node,
level,
match nr.element().borrow().bindings.get(nr.name()) {
None => {
debug_assert!(
diag.as_ref().map_or(true, |d| d.has_errors()),
"private functions must be local and defined"
);
}
r = false;
Some(binding) => {
if !ensure_pure(
&binding.borrow().expression,
None,
level,
recursion_test,
) {
if let Some(diag) = diag.as_deref_mut() {
diag.push_diagnostic(
format!("Call of impure function '{}'", nr.name()),
node,
level,
);
}
r = false;
}
}
}
recursion_test.remove(nr);
}
}
}

View file

@ -0,0 +1,14 @@
// 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
Compo1:=R{property<int b;function bb)i{}}c:=Compo1{b:self.bb
// ^error{Syntax error: expected '>'}
// ^^error{Syntax error: expected '\('}
// ^^^error{Syntax error: expected '\{'}
// ^^^^error{invalid expression}
// ^^^^^error{Syntax error: expected '\}'}
// ^^^^^^error{Parse error}
}
// ^error{Syntax error: expected ';'}
/**/