From bf70d807b320a0d058b5a92fe455ccfa4340f159 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 27 Dec 2023 11:38:51 +0100 Subject: [PATCH] Fix compiler panic when using `%` size in a flickable The viewport of a flickable is of ElementType::Native, and `lookup_property` don't query the builtin reserved properties in that case. This commit fix the assert by allowing Type::Invalid as well. Fixes #4163 --- internal/compiler/passes/default_geometry.rs | 6 +- .../issue_4163_flickable_parent_percent.slint | 57 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/cases/issues/issue_4163_flickable_parent_percent.slint diff --git a/internal/compiler/passes/default_geometry.rs b/internal/compiler/passes/default_geometry.rs index 75d6698e171..c2153b7af92 100644 --- a/internal/compiler/passes/default_geometry.rs +++ b/internal/compiler/passes/default_geometry.rs @@ -278,10 +278,10 @@ fn fix_percent_size( } let mut b = binding.borrow_mut(); if let Some(parent) = parent { - debug_assert_eq!( + debug_assert!(matches!( parent.borrow().lookup_property(property).property_type, - Type::LogicalLength - ); + Type::LogicalLength | Type::Invalid + )); let fill = matches!(b.expression, Expression::NumberLiteral(x, _) if (x - 100.).abs() < 0.001); b.expression = Expression::BinaryExpression { diff --git a/tests/cases/issues/issue_4163_flickable_parent_percent.slint b/tests/cases/issues/issue_4163_flickable_parent_percent.slint new file mode 100644 index 00000000000..ef404a3c87f --- /dev/null +++ b/tests/cases/issues/issue_4163_flickable_parent_percent.slint @@ -0,0 +1,57 @@ +import { ListView } from "std-widgets.slint"; +component ShowResult inherits Rectangle { + width: 50%; + height: 100%; + + VerticalLayout { + ListView { + for file[idx] in [1,2,3]:Rectangle { + height: 20px; + // width: parent.width; // change to this line compiles fine + width: 100%; // An error occurred!!! + } + } + } +} +export component TestCase inherits Window { + width: 326px; + height: 326px; + + HorizontalLayout { + width: 100%; + height: 100%; + + ShowResult {} + } + + + fli := Flickable { + viewport-height: 1000px; + viewport-width: 2000px; + rec := Rectangle { + width: 100%; + height: parent.height; + } + } + + out property test: + // The % applies to the viewport + rec.width == 2000px && + // While the parent applies to the flickable + rec.height == 326px; +} + +/* + +```cpp +auto handle = TestCase::create(); +const TestCase &instance = *handle; +assert(instance.get_test()); +``` + +```rust +let instance = TestCase::new().unwrap(); +assert!(instance.get_test()); +``` + +*/