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

Compile error in cube type impl if struct behind conditional #333

Open
torsteingrindvik opened this issue Dec 1, 2024 · 0 comments
Open

Comments

@torsteingrindvik
Copy link
Contributor

I minified an example to roughly the methods foo and bar in the code below.
I'd expect them both to work since they achieve similar things but only bar works.

#[derive(CubeType)]
struct Foo {
    a: f32,
}

#[cube]
impl Foo {
    // mismatched types
    // expected struct `ExpandElementTyped<_>`
    //    found struct `FooExpand`
    pub fn foo(&self, v: u32) -> Foo {
        if v > 0 {
            Foo { a: 1.0 }
        } else {
            Foo { a: 0.0 }
        }
    }

    // ok
    pub fn bar(&self, v: u32) -> Foo {
        let mut foo = Foo { a: 0.0 };

        if v > 0 {
            foo.a = 1.0
        }

        foo
    }
}

I'm guessing this is related to the conditional in the expansion, see image:

image

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

No branches or pull requests

1 participant