Compiler: fix conversion from unnamed to named struct

Fixes #2765
This commit is contained in:
Olivier Goffart 2023-09-07 11:44:40 +02:00 committed by Olivier Goffart
parent 4fa983522e
commit f73c1cf80d
2 changed files with 21 additions and 9 deletions

View file

@ -1059,8 +1059,8 @@ impl Expression {
op: '*',
},
(
Type::Struct { fields: ref left, .. },
Type::Struct { fields: right, name, node: n, rust_attributes },
ref from_ty @ Type::Struct { fields: ref left, .. },
Type::Struct { fields: right, .. },
) if left != right => {
if let Expression::Struct { mut values, .. } = self {
let mut new_values = HashMap::new();
@ -1080,12 +1080,7 @@ impl Expression {
Expression::StructFieldAccess {
base: Box::new(Expression::ReadLocalVariable {
name: var_name.into(),
ty: Type::Struct {
fields: left.clone(),
name: name.clone(),
node: n.clone(),
rust_attributes: rust_attributes.clone(),
},
ty: from_ty.clone(),
}),
name: key.clone(),
}

View file

@ -7,9 +7,14 @@ struct Foo1 { member: int, }
struct Foo2 { a: Foo1 }
struct Foo3 { b: int }
struct DeleteMe { c: color }
struct Palette {
menuBar : brush,
mainContent : brush,
box : brush,
}
export component TestCase inherits Rectangle {
pure callback cb1(Foo2) -> Foo3;
cb1(foo) => { return { b: foo.a.member+1 }; }
@ -24,6 +29,18 @@ export component TestCase inherits Rectangle {
property<[DeleteMe]> data;
for d[i] in self.data: Rectangle { }
}
// Bug #2765
out property<Palette> palette : xx.a.member > 32 ? {
menuBar : #6D7BFB,
mainContent : #fbfbfb,
box : #ffffff,
} : {
menuBar : #2937A7,
mainContent : #040404,
box : #000000,
};
}