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

if conditional in component attribute evaluating one leg as &str and other as String, when interpolation in only one leg #2997

Open
3 tasks
rogusdev opened this issue Sep 25, 2024 · 1 comment · May be fixed by #2999
Assignees
Labels
bug Something isn't working rsx Related to rsx or the dioxus-rsx crate

Comments

@rogusdev
Copy link
Sponsor Contributor

rogusdev commented Sep 25, 2024

Problem

src: if lang_code() == "en" { "image.png" } else { "{lang_code()}/image.png" }

Errors with:

error[E0308]: `if` and `else` have incompatible types
...
 expected `&str`, found `String`

But this works:

src: if lang_code() == "en" { "image.png".to_string() } else { "{lang_code()}/image.png" }

However @ealmloff agrees that this should be handled automatically by the rsx:
https://discord.com/channels/899851952891002890/1288251857457647698/1288288455960301690

Environment:

  • Dioxus version: main
  • App platform: web

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@ealmloff ealmloff added bug Something isn't working rsx Related to rsx or the dioxus-rsx crate labels Sep 25, 2024
@ealmloff ealmloff self-assigned this Sep 25, 2024
@ealmloff ealmloff linked a pull request Sep 25, 2024 that will close this issue
@chungwong
Copy link
Contributor

Does it mean the types in the if branches can now be different? Isn't this not very Rusty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rsx Related to rsx or the dioxus-rsx crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants