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

Use of generics returns a confusing error #979

Closed
miraclx opened this issue Nov 26, 2022 · 2 comments · Fixed by #980
Closed

Use of generics returns a confusing error #979

miraclx opened this issue Nov 26, 2022 · 2 comments · Fixed by #980

Comments

@miraclx
Copy link
Contributor

miraclx commented Nov 26, 2022

We should consider returning a neater error message stating that generics aren't supported, instead of the confusing error it currently returns.

Especially since, it's perfectly valid code without the #[near_bindgen] attr.

#[near_bindgen]
impl MyType {
    pub fn method<T>(arg: T) -> T { ... }
}
$ cargo build
   Compiling contract v0.1.0 (/path/to/contract)
error[E0401]: can't use generic parameters from outer function
  --> src/lib.rs:10:28
   |
10 |     pub fn method<T>(data: T) -> T {
   |            ---------       ^ use of generic parameter from outer function
   |            |      |
   |            |      type parameter from outer function
   |            help: try using a local generic parameter instead: `method<T, T>`

For more information about this error, try `rustc --explain E0401`.
error: could not compile `contract` due to previous error

But technically, it's clear what the hurdle will be here. It's understandably tricky disambiguating between generic identifiers and explicitly typed ones. Would be interesting to investigate.

@miraclx
Copy link
Contributor Author

miraclx commented Nov 26, 2022

One option is to just disable the declaration of generics in public functions altogether. Unsure if there's a use-case for them anyway. I can't personally think of any patterns that require them.

impl<N> MyType<N> already returns Impl type parameters are not supported for smart contracts.

@itegulov
Copy link
Contributor

Yeah just feels like an oversight to me, opened a quick PR

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

Successfully merging a pull request may close this issue.

2 participants