Skip to content

Commit

Permalink
Fix panic with invalid code
Browse files Browse the repository at this point in the history
Fix #6518
  • Loading branch information
ogoffart committed Oct 15, 2024
1 parent 4718d5b commit f0e02a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
41 changes: 22 additions & 19 deletions internal/compiler/passes/purity_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions internal/compiler/tests/syntax/fuzzing/6518.slint
Original file line number Diff line number Diff line change
@@ -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 ';'}
/**/

0 comments on commit f0e02a3

Please sign in to comment.