Skip to content

Fix conditional assignment of arrays of structs - #12845

Open
Murmele wants to merge 5 commits into
slint-ui:masterfrom
Murmele:mm/conditional_struct_array
Open

Fix conditional assignment of arrays of structs#12845
Murmele wants to merge 5 commits into
slint-ui:masterfrom
Murmele:mm/conditional_struct_array

Conversation

@Murmele

@Murmele Murmele commented Aug 10, 2026

Copy link
Copy Markdown
Member
  • If the change modifies a visible behavior, it changes the documentation accordingly
  • If possible, the change is auto-tested
  • If the changes fixes or close an existing issue, the commit message reference the issue with Fixes #xxx or Closes #xxx
  • If the change is noteworthy, the commit message should contain ChangeLog: ...

@Murmele
Murmele requested review from ogoffart and removed request for ogoffart August 10, 2026 13:45
@Murmele
Murmele marked this pull request as draft August 10, 2026 13:47
@Murmele
Murmele marked this pull request as ready for review August 10, 2026 13:50
@Murmele
Murmele requested review from ogoffart and removed request for ogoffart August 10, 2026 13:50
@Murmele
Murmele marked this pull request as draft August 10, 2026 15:26

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should limit the scope to only check for array type because otherwise we get duplicate error message.

and i think we also need more than just condition, for example we'd have the same problem with struct literal, don't we?

Reason: otherwise we get duplicate errors
@Murmele

Murmele commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

we should limit the scope to only check for array type because otherwise we get duplicate error message.

and i think we also need more than just condition, for example we'd have the same problem with struct literal, don't we?

Thanks for the hint. This was probably the unittest issue I got.

Do you mean

struct Data {
    text: string,
}

export component TestCase inherits Window {
    in-out property <bool> test: true;
    out property <string> data_text: data.text;

    out property<Data> data: test ? {
        text: "Test true",
    } : {
        text: "Test false"
    };
}

This case is covered because ty.can_convert(&target_type) returns true

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a syntax test like

in property <[int]> error;
out property <[Data]> data: test ? error : error; 

And we should ideally only have one error, not 2.

}
}
if constexpr (HasFromSlintValue<ModelData>) {
if (auto array = value.to_array(); array && array->size() > 0) {

@ogoffart ogoffart Aug 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot why i added a size > 0 test in 0700b83. But yeah, that seems correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants