Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@linear-gradient macro broken in ternary operator #1235

Closed
levrik opened this issue May 5, 2022 · 2 comments · Fixed by #1241
Closed

@linear-gradient macro broken in ternary operator #1235

levrik opened this issue May 5, 2022 · 2 comments · Fixed by #1241
Assignees
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) bug Something isn't working

Comments

@levrik
Copy link
Contributor

levrik commented May 5, 2022

When using the @linear-gradient macro in the 2nd position of the ternary operator, just the first color value found is being used.

Rectangle { 
    background: true ? @linear-gradient(90deg, #fff 0%, #000 100%) : #000;
}

image

Rectangle { 
    background: false ? #000 : @linear-gradient(90deg, #fff 0%, #000 100%);
}

image

I simplified the code a lot for demonstration purposes.

These 2 codeblocks can be just copied into Window of https://slint-ui.com/releases/0.2.2/editor/ to reproduce.

I could work around by moving the gradients into a global and just reference it from inside the ternary operator. Looks like a bug in the parser to me.

Edit: Above statement isn't true. It's also not working when using a global.

@levrik levrik changed the title @linear-gradient broken when used in 2nd position of ternary operator @linear-gradient macro broken in ternary operator May 5, 2022
@ogoffart ogoffart added bug Something isn't working a:compiler Slint compiler internal (not the codegen, not the parser) labels May 6, 2022
@ogoffart ogoffart self-assigned this May 6, 2022
@ogoffart
Copy link
Member

ogoffart commented May 6, 2022

Thanks for the report.
Looks like the ternary operator always convert to the type of the first operand when both ways are possible.

Will look into it.

@levrik
Copy link
Contributor Author

levrik commented May 6, 2022

@ogoffart Ah, this makes sense. Thanks a lot! I've worked around by ensuring that the gradient always comes first for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:compiler Slint compiler internal (not the codegen, not the parser) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants