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

Expression type is ambigious when using trait generics that instantiate variables #5063

Closed
vezenovm opened this issue May 21, 2024 · 0 comments · Fixed by #5087
Closed

Expression type is ambigious when using trait generics that instantiate variables #5063

vezenovm opened this issue May 21, 2024 · 0 comments · Fixed by #5087
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate

Comments

@vezenovm
Copy link
Contributor

Aim

After the addition of the turbofish operator (#3542) we should be able to use trait generics without them being bound to a parameter or return value.

I want to be able to use a trait generic to instantiate an object using its trait methods and then further use those trait methods. For example the following code should work (after #5041):

fn hash_simple_array<H>(input: [Field; 2]) -> Field where H: Hasher + Default {
    let mut hasher = H::default();
    hasher.write(input[0]);
    hasher.write(input[1]);
    hasher.finish()
}

Expected Behavior

The program above should pass.

Bug

Instead when attempting to use the result of H::default() we get an error Expression type is ambiguous.
Screenshot 2024-05-21 at 1 14 44 PM

To Reproduce

  1. Compile the snippet above

Project Impact

Blocker

Impact Context

This blocks us being able to document and advertise turbofish

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@vezenovm vezenovm added bug Something isn't working compiler frontend `noirc_frontend` crate labels May 21, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 21, 2024
@vezenovm vezenovm changed the title Expression type is ambigious when using trait generics that instantiate variabels Expression type is ambigious when using trait generics that instantiate variables May 21, 2024
github-merge-queue bot pushed a commit that referenced this issue May 23, 2024
…ng identifiers (#5087)

# Description

## Problem\*

Resolves #5063 

## Summary\*

After the turbofish PRs we want the ability to instantiate a variable
from a generic trait. This was possible but it required a redundant type
annotiation like such (assume `H` has been specified with a `where`
clause):
```rust
let hasher: H = H::default()
```
Similarly to trait generics, we now add type bindings from a trait
constraint if the trait impl is assumed to exist.
We now can just do:
```rust
let hasher = H::default()
```

## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant