Remove the check_aliases pass

The behavior has now changed, so no need for the warning

cc #1394
This commit is contained in:
Olivier Goffart 2022-11-04 11:45:32 +01:00 committed by Olivier Goffart
parent 425b477874
commit f4bd77461d
3 changed files with 0 additions and 140 deletions

View file

@ -3,7 +3,6 @@
mod apply_default_properties_from_style;
mod binding_analysis;
mod check_aliases;
mod check_expressions;
mod check_public_api;
mod check_rotation;
@ -93,7 +92,6 @@ pub async fn run_passes(
diag,
);
lower_states::lower_states(component, &doc.local_registry, diag);
check_aliases::check_aliases(component, diag)
}
inlining::inline(doc, inlining::InlineSelection::InlineOnlyRequiredComponents);

View file

@ -1,62 +0,0 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
//! Verify that aliases have proper default values
use crate::diagnostics::BuildDiagnostics;
use crate::expression_tree::Expression;
use crate::langtype::ElementType;
use crate::object_tree::{Component, ElementRc};
use std::rc::Rc;
pub fn check_aliases(component: &Rc<Component>, diag: &mut BuildDiagnostics) {
crate::object_tree::recurse_elem_including_sub_components(&component, &(), &mut |elem, _| {
let base = if let ElementType::Component(base) = &elem.borrow().base_type {
base.clone()
} else {
return;
};
for (prop, b) in &elem.borrow().bindings {
if b.borrow().two_way_bindings.is_empty() {
continue;
}
if let Some(lhs_prio) = explicit_binding_priority(&base.root_element, prop) {
for nr in &b.borrow().two_way_bindings {
if explicit_binding_priority(&nr.element(), nr.name())
.map_or(true, |rhs_prio| rhs_prio > lhs_prio.saturating_add(1))
{
diag.push_warning(
format!(
r#"Two way binding between the property '{prop}' with a default value to the property '{nr:?}' without value.
The current behavior is to keep the value from the left-hand-side, but this behavior will change in the next version to always keep the right-hand-side value.
This may cause panic at runtime. See https://github.com/slint-ui/slint/issues/1394
To fix this warning, add a default value to the property '{nr:?}'"#,
),
&b.borrow().span);
}
}
}
}
});
}
/// Return whether the property has an actual binding value set,
/// in that case return its priority
fn explicit_binding_priority(elem: &ElementRc, name: &str) -> Option<i32> {
if let Some(b) = elem.borrow().bindings.get(name) {
if !matches!(b.borrow().expression, Expression::Invalid) {
Some(b.borrow().priority)
} else {
for nr in &b.borrow().two_way_bindings {
if let Some(p) = explicit_binding_priority(&nr.element(), nr.name()) {
return Some(p.saturating_add(b.borrow().priority) - 1);
}
}
None
}
} else if let ElementType::Component(base) = &elem.borrow().base_type {
explicit_binding_priority(&base.root_element, name).map(|p| p.saturating_add(1))
} else {
None
}
}

View file

@ -1,76 +0,0 @@
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
Sub := Rectangle {
property <string> no_default;
property <string> alias_no_default <=> t1.text;
property <string> alias_default <=> t2.text;
property <string> default: "Def";
property <string> state_prop;
t1 := Text { }
t2 := Text { text: "Hello"; }
states [
X when false : { state_prop: "state"; }
]
}
Interm := Sub {}
X := Rectangle {
property <string> some_value: "Hello";
property <string> b1;
Sub { no_default <=> b1; }
property <string> b2;
Sub { alias_no_default <=> b2; }
property <string> b3;
Sub { alias_default <=> b3; }
// ^warning{Two way binding between the property 'alias-default' with a default value to the property 'root.b3' without value.}
property <string> b4;
Sub { default <=> b4; }
// ^warning{Two way binding between the property 'default' with a default value to the property 'root.b4' without value.}
property <string> b5: "Val";
Sub { default <=> b5; }
property <string> b6 <=> s6.default;
s6 := Sub { }
s7 := Sub {}
Sub {
default <=> s7.no-default;
// ^warning{Two way binding between the property 'default' with a default value to the property 's7.no-default' without value.}
no-default <=> s7.default;
}
property <string> b8;
property <string> b9 <=> some_value;
if false: Sub {
state_prop <=> b8;
// ^warning{Two way binding between the property 'state-prop' with a default value to the property 'root.b8' without value.}
Sub { state_prop <=> b9; }
}
s10 := Interm {}
s11 := Interm {
default: "";
state_prop <=> s10.default;
alias_default <=> s10.alias-no-default;
// ^warning{Two way binding between the property 'alias-default' with a default value to the property 's10.alias-no-default' without value.}
Sub {
alias-default <=> s10.default;
// ^warning{Two way binding between the property 'alias-default' with a default value to the property 's10.default' without value.}
default <=> s11.default;
}
}
}