diff --git a/sixtyfps_runtime/interpreter/global_component.rs b/sixtyfps_runtime/interpreter/global_component.rs index d3ab57d35..1cd8aac68 100644 --- a/sixtyfps_runtime/interpreter/global_component.rs +++ b/sixtyfps_runtime/interpreter/global_component.rs @@ -15,7 +15,7 @@ use std::rc::Rc; use crate::api::{Struct, Value}; use crate::eval; -use sixtyfps_compilerlib::{langtype::Type, object_tree::Component}; +use sixtyfps_compilerlib::{generator, langtype::Type, object_tree::Component}; use sixtyfps_corelib::{rtti, Callback, Property}; pub trait GlobalComponent { @@ -85,8 +85,8 @@ impl GlobalComponentInstance { } } let rc = Rc::pin(instance); - for (k, expr) in &component.root_element.borrow().bindings { - if expr.expression.is_constant() { + generator::handle_property_bindings_init(component, |_, k, expr| { + if expr.analysis.borrow().as_ref().map_or(false, |a| a.is_const) { rc.properties[k].as_ref().set(eval::eval_expression( &expr.expression, &mut eval::EvalLocalContext::from_global(&(rc.clone() as _)), @@ -103,7 +103,7 @@ impl GlobalComponentInstance { ) }); } - } + }); rc } } diff --git a/tests/cases/globals/global_binding.60 b/tests/cases/globals/global_binding.60 index 4c1f67621..f0446d9b5 100644 --- a/tests/cases/globals/global_binding.60 +++ b/tests/cases/globals/global_binding.60 @@ -18,6 +18,7 @@ TestCase := Rectangle { callback set_a(int); set_a(a) => { Glob.a = a; } property value1: Glob.b; + property test: value1 == 3+3; } /* diff --git a/tests/cases/globals/global_binding_const.60 b/tests/cases/globals/global_binding_const.60 new file mode 100644 index 000000000..54b0390a9 --- /dev/null +++ b/tests/cases/globals/global_binding_const.60 @@ -0,0 +1,48 @@ +/* LICENSE BEGIN + This file is part of the SixtyFPS Project -- https://sixtyfps.io + Copyright (c) 2020 Olivier Goffart + Copyright (c) 2020 Simon Hausmann + + SPDX-License-Identifier: GPL-3.0-only + This file is also available under commercial licensing terms. + Please contact info@sixtyfps.io for more information. +LICENSE END */ + +// This tests that constant property from global are properly initialized + +global Glob := { + property a: 3; + property b: a + 3; +} + +global Glob2 := { + property a: other; + property other: 5; +} + +TestCase := Rectangle { + r := Rectangle { + property value1: Glob.b; + property value2: true ? Glob2.a : 88; + } + property test: r.value1 + r.value2 == 3+3 +5; +} + +/* +```rust +let instance = TestCase::new(); +assert!(instance.get_test()); +``` + +```cpp +auto handle = TestCase::create(); +const TestCase &instance = *handle; +assert(instance.get_test()); +``` + +```js +let instance = new sixtyfps.TestCase({}); +assert(instance.test); +``` + +*/