From f0e02a3aa32bee42b57d409f572dbd83ae227aa6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 15 Oct 2024 11:15:41 +0200 Subject: [PATCH] Fix panic with invalid code Fix #6518 --- internal/compiler/passes/purity_check.rs | 41 ++++++++++--------- .../compiler/tests/syntax/fuzzing/6518.slint | 14 +++++++ 2 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 internal/compiler/tests/syntax/fuzzing/6518.slint diff --git a/internal/compiler/passes/purity_check.rs b/internal/compiler/passes/purity_check.rs index efdb7aa5981..fcd8fdc22a5 100644 --- a/internal/compiler/passes/purity_check.rs +++ b/internal/compiler/passes/purity_check.rs @@ -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); } } } diff --git a/internal/compiler/tests/syntax/fuzzing/6518.slint b/internal/compiler/tests/syntax/fuzzing/6518.slint new file mode 100644 index 00000000000..362a90967ae --- /dev/null +++ b/internal/compiler/tests/syntax/fuzzing/6518.slint @@ -0,0 +1,14 @@ +// Copyright © SixtyFPS GmbH +// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 + +Compo1:=R{property'} +// ^^error{Syntax error: expected '\('} +// ^^^error{Syntax error: expected '\{'} +// ^^^^error{invalid expression} +// ^^^^^error{Syntax error: expected '\}'} +// ^^^^^^error{Parse error} + + } +// ^error{Syntax error: expected ';'} + /**/