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

Rust error "non-primitive cast" with a weird key-pressed handler #4942

Closed
elipsitz opened this issue Mar 26, 2024 · 3 comments · Fixed by #4949
Closed

Rust error "non-primitive cast" with a weird key-pressed handler #4942

elipsitz opened this issue Mar 26, 2024 · 3 comments · Fixed by #4949
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working

Comments

@elipsitz
Copy link
Contributor

elipsitz commented Mar 26, 2024

Adding the following code to a .slint (I just did the template and it repro'd)

    FocusScope {
        key-pressed(event) => {
            if (event.text == "a") {
                accept
            }
            reject
        }
    }

causes a Rust compilation error:

    --> .../slint-bug-1-f45ed77926121a04/out/appwindow.rs:2471:34
     |
2471 | / ...                    ({
2472 | | ...                        }
2473 | | ...                   ) as _ }
     | |____________________________^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

For more information about this error, try `rustc --explain E0605`.
error: could not compile `slint-bug-1` (bin "slint-bug-1") due to 1 previous error

I'm using Slint 1.5.1 on macOS, with Rust.

This looks very similar to #3962

@tronical
Copy link
Member

Oops, that looks like a bug to me. I can reproduce this. That said, I think there's also a bug in your code :-), which has the positive side-effect that it'll work around the bug and make it work as you probably expected:

    FocusScope {
        key-pressed(event) => {
            if (event.text == "a") {
                return accept; // <-- The return statement was missing here :-)
            }
            reject
        }
    }

@tronical tronical added bug Something isn't working a:language-rust Rust API and codegen (mO,mS) labels Mar 26, 2024
@ogoffart
Copy link
Member

We probably should make a warning for statement that don't do anything.

@ogoffart
Copy link
Member

ogoffart commented Mar 27, 2024

The rust compilation error is fixed. But opened #4954 to add a warning on useless statements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-rust Rust API and codegen (mO,mS) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants