Skip to content

Commit

Permalink
Fix compiler panic when using % size in a flickable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ogoffart committed Dec 27, 2023
1 parent 5aa6b42 commit bf70d80
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/compiler/passes/default_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions tests/cases/issues/issue_4163_flickable_parent_percent.slint
Original file line number Diff line number Diff line change
@@ -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 <bool> 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());
```
*/

0 comments on commit bf70d80

Please sign in to comment.