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

Implement basic type inference for generic structs and functions #178

Open
edg-l opened this issue Feb 12, 2025 · 0 comments
Open

Implement basic type inference for generic structs and functions #178

edg-l opened this issue Feb 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@edg-l
Copy link
Member

edg-l commented Feb 12, 2025

mod MyMod {
    struct GenericStruct<T> {
        a: T,
        b: u32,
    }

    pub fn main() -> i32 {
        let value: GenericStruct<i32> = GenericStruct::<i32> {
            a: 2,
            b: 4,
        };

        return value.a;
    }
}

Currently for generic structs and functions, the types need to be specified while they could be reasonably infered by the arguments used.

So this would turn into

mod MyMod {
    struct GenericStruct<T> {
        a: T,
        b: u32,
    }

    pub fn main() -> i32 {
        // Maybe we can even infer let types completely too.
        let value: GenericStruct<i32> = GenericStruct {
            a: 2,
            b: 4,
        };

        return value.a;
    }
}
@edg-l edg-l added the enhancement New feature or request label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant