Skip to content

having a variable named 'args' in a function leads to weird error messages #827

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

Closed
beevans opened this issue Dec 14, 2020 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@beevans
Copy link

beevans commented Dec 14, 2020

I had a variable I'd named "args" in a function. It lead to a whole bunch of compile errors on an unrelated variable when the juniper::graphql_object macro was unpacked.

It would be nice to have an error message that detects reserved words in an argument list.

@beevans beevans added bug Something isn't working needs-triage labels Dec 14, 2020
@LegNeato
Copy link
Member

We should make these hermetic or mangle the names to make it work.

@LegNeato
Copy link
Member

LegNeato commented Dec 16, 2020

Do you happen to have a quick repro and the error message?

@beevans
Copy link
Author

beevans commented Dec 16, 2020

I had a function whose header was basically this:

#[juniper::graphql_object(Context = Context)]
impl TestMutation {
async fn run_task_test(
context: &Context,
jobname: String,
taskname: String,
fsname: String,
args: String,
fidlist: Vec,
) -> juniper::FieldResult {
func(fidlist);
};
....

The errors were:

error[E0277]: the type str cannot be indexed by std::vec::Vec<std::string::String>
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string indices are ranges of usize
|
= help: the trait std::slice::SliceIndex<str> is not implemented for std::vec::Vec<std::string::String>
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct std::vec::Vec, found &str
|
= note: expected struct std::vec::Vec<std::string::String>
found reference &‘static str
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound &_: juniper::FromInputValue is not satisfied
--> example.rs:57:1
|
57 | #[juniper::graphql_object(Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait juniper::FromInputValue is not implemented for &_
|
::: /root/.cargo/git/checkouts/juniper-aa5e857cd28538c7/6326acd/juniper/src/ast.rs:153:1
|
153 | pub trait FromInputValue<S = DefaultScalarValue>: Sized {
| ------------------------------------------------------- required by this bound in juniper::FromInputValue::from_implicit_null
|
= help: the following implementations were found:
<bool as juniper::FromInputValue>
<bson::bson::DateTime as juniper::FromInputValue>
<bson::oid::ObjectId as juniper::FromInputValue>
<chrono::DateTimechrono::FixedOffset as juniper::FromInputValue>
and 27 others
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try rustc --explain E0277.
error: could not compile example.

@beevans
Copy link
Author

beevans commented Dec 16, 2020

As you can see errors don't really point to "try renaming 'args'" as the solution.

@tyranron
Copy link
Member

Again, as some other issues, this should be fixed once we desugar computed object fields as method call, not inline closure.

@tyranron tyranron self-assigned this Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants