slint/tests/cases/globals/global_binding_const.slint
Olivier Goffart 86978e9fc1
Rust generated: fix constant non-inlined global
We must take care that all access to property that we consider constant
in global are accessed after the global has been initialized.

So initialize the global before the properties.

Fixes #8375 , #8337
2025-05-05 18:55:19 +02:00

51 lines
1.3 KiB
Text

// 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
// This tests that constant property from global are properly initialized
global Glob {
in-out property <int> a: 3;
in-out property <int> b: a + 3;
}
global Glob2 {
in-out property <int> a: other;
in-out property <int> other: 5;
// A constant property that is not going to be inlined
out property <int> const-no-inline: {
debug("this debug message should make no-inline to not be inlined");
82
}
}
export component TestCase inherits Window {
r := Rectangle {
property <int> value1: Glob.b;
property <int> value2: true ? Glob2.a : 88;
}
out property <int> value3: Glob2.const-no-inline;
out property <bool> test: r.value1 + r.value2 == 3+3 +5 && value3 == 82;
}
/*
```rust
let instance = TestCase::new().unwrap();
assert_eq!(instance.get_value3(), 82);
assert!(instance.get_test());
```
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert_eq(instance.get_value3(), 82);
assert(instance.get_test());
```
```js
let instance = new slint.TestCase({});
assert.equal(instance.value3, 82);
assert(instance.test);
```
*/