mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 02:13:21 +00:00
Fix conversions of array literal containing struct with array literal
Fixes #2023
This commit is contained in:
parent
8edc7f669a
commit
8d7b8df922
3 changed files with 22 additions and 3 deletions
|
@ -1075,15 +1075,17 @@ impl Expression {
|
|||
},
|
||||
};
|
||||
Expression::Cast { from: Box::new(from), to: target_type }
|
||||
} else if matches!((&ty, &target_type, &self), (Type::Array(left), Type::Array(right), Expression::Array{..})
|
||||
if left.can_convert(right) || **left == Type::Invalid)
|
||||
{
|
||||
} else if matches!(
|
||||
(&ty, &target_type, &self),
|
||||
(Type::Array(_), Type::Array(_), Expression::Array { .. })
|
||||
) {
|
||||
// Special case for converting array literals
|
||||
match (self, target_type) {
|
||||
(Expression::Array { values, .. }, Type::Array(target_type)) => Expression::Array {
|
||||
values: values
|
||||
.into_iter()
|
||||
.map(|e| e.maybe_convert_to((*target_type).clone(), node, diag))
|
||||
.take_while(|e| !matches!(e, Expression::Invalid))
|
||||
.collect(),
|
||||
element_ty: *target_type,
|
||||
},
|
||||
|
|
|
@ -45,4 +45,8 @@ X := Rectangle {
|
|||
|
||||
property <{a: string, b: int}> object1: { a: "123", typo: 42};
|
||||
// ^error{Cannot convert \{ a: string,typo: float,\} to \{ a: string,b: int,\}}
|
||||
|
||||
property <[{a: [int]}]> ccc: [{a: []}, {}, {a: ["123"]}, {a: [123]}];
|
||||
// ^error{Cannot convert string to int} (FIXME: error location)
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
||||
|
||||
|
||||
export struct Player := {
|
||||
skill-profile: int,
|
||||
}
|
||||
export struct NewGameTeam := {
|
||||
players: [Player],
|
||||
}
|
||||
export struct NewGameParameters := {
|
||||
teams: [NewGameTeam],
|
||||
}
|
||||
|
||||
|
||||
struct StructWithArrayOfStruct := { prop: [{hello: string, world: int}], xxx: int }
|
||||
|
||||
TestCase := Rectangle {
|
||||
|
@ -10,6 +21,8 @@ TestCase := Rectangle {
|
|||
property <[string]> p3 : [ ];
|
||||
property <[{a: int, b: int}]> p4 : [ { a: 1 }, { a: 42, b: 10 } ];
|
||||
property <StructWithArrayOfStruct> p5 : { prop: [{hello: "hello"}, {world: 42.0 }]};
|
||||
|
||||
property <NewGameParameters> p6 : { teams: [{ players: [ { skill-profile: 9 } ] }] } ;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue