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

#[func] function arguments with invalid types produce weird errors #691

Open
lilizoey opened this issue May 3, 2024 · 0 comments
Open
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals

Comments

@lilizoey
Copy link
Member

lilizoey commented May 3, 2024

A function defined like this:

#[godot_api]
impl Bar {
    #[func]
    fn add_two(&mut self, my_param: &String) {}
}

Produces a "missing lifetime specifier" error

Screenshot_20240503_183427

Which is because the macro does type Sig = ((), &String) which then produces a missing lifetime error. We could instead produce an error in the macro when a reference is used in an argument's type (except for the receiver).


Additionally rust-analyzer produces a "non-exhaustive pattern" error

Screenshot_20240503_183115

This is because when R-A to find an implementation of the *Signature traits for ((), &String) it will assume the Params associated type is ((), &String) instead of (&String,) as intended. This leads to us trying to destruct a ((), &String) using (my_param,) pattern.

One solution could be to create a struct Signature<Ret, Params> { .. } type which we use instead of a pure tuple. Then the macro could explicitly set the return value and the arguments separately.


For a function like this where the invalid argument isn't a reference:

#[godot_api]
impl Bar {
    #[func]
    fn add_two(&mut self, my_param: Vec<String>) {}
}

The error is instead that Vec<String> doesn't implement ToGodot/FromGodot as expected, however the error is displayed on the godot_api attribute, instead of on the Vec<String> argument type as i would expect.
Screenshot_20240503_184234

(the my_param error is the R-A error from above)

@lilizoey lilizoey added quality-of-life No new functionality, but improves ergonomics/internals c: register Register classes, functions and other symbols to GDScript labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: register Register classes, functions and other symbols to GDScript quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

No branches or pull requests

1 participant