mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 18:58:36 +00:00
parent
3a9fe1d161
commit
6622f33327
2 changed files with 23 additions and 0 deletions
|
@ -993,6 +993,24 @@ impl Expression {
|
|||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else if let (Type::Struct { fields, .. }, Expression::Struct { values, .. }) =
|
||||
(&target_type, &self)
|
||||
{
|
||||
// Also special case struct literal in case they contain array literal
|
||||
let mut fields = fields.clone();
|
||||
let mut new_values = HashMap::new();
|
||||
for (f, v) in values {
|
||||
if let Some(t) = fields.remove(f) {
|
||||
new_values.insert(f.clone(), v.clone().maybe_convert_to(t, node, diag));
|
||||
} else {
|
||||
diag.push_error(format!("Cannot convert {} to {}", ty, target_type), node);
|
||||
return self;
|
||||
}
|
||||
}
|
||||
for (f, t) in fields {
|
||||
new_values.insert(f, Expression::default_value_for_type(&t));
|
||||
}
|
||||
Expression::Struct { ty: target_type, values: new_values }
|
||||
} else {
|
||||
let mut message = format!("Cannot convert {} to {}", ty, target_type);
|
||||
// Explicit error message for unit conversion
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue