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

Static trait method references lead to a compiler panic #3773

Closed
jfecher opened this issue Dec 11, 2023 · 0 comments · Fixed by #3774
Closed

Static trait method references lead to a compiler panic #3773

jfecher opened this issue Dec 11, 2023 · 0 comments · Fixed by #3774
Assignees
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate

Comments

@jfecher
Copy link
Contributor

jfecher commented Dec 11, 2023

Aim

Referencing a trait method via the trait name, rather than a struct name. E.g. Default::default() instead of MyStruct::default().

Expected Behavior

Identical behavior to MyStruct::default() except with the impl being selected via type inference rather than the struct name.

Bug

Compiler panic that Default::default() does not have a FuncMeta stored in the NodeInterner.

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@jfecher jfecher added bug Something isn't working compiler frontend `noirc_frontend` crate P-MEDIUM labels Dec 11, 2023
@jfecher jfecher self-assigned this Dec 11, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 13, 2023
# Description

## Problem\*

Resolves #3773
Part of #2568 

## Summary\*

This PR implements the ability to be able to call trait methods such as
`Default::default()` where previously we required
`StructName::default()`. The specific impl is selected via type
inference. Previously, this resulted in a compiler panic.

## Additional Context

When a trait method's type isn't constrained enough or is otherwise
still ambiguous after type inference, the compiler currently just
selects the first trait implementation that matches. E.g. `let _ =
Default::default();`. This is a separate issue, so I'll create a new
issue for this.

## Documentation\*

Check one:
- [ ] No documentation needed. 
- [ ] Documentation included in this PR.
- [x] **[Exceptional Case]** Documentation to be submitted in a separate
PR.
- I think traits are finally stable enough to start writing
documentation for. I'm going to submit another PR to remove some of the
experimental warnings the compiler has for traits, and with it add
documentation for traits as well. This wouldn't stabilize all trait
features (e.g. associated types are still unimplemented), but users will
now be able to use basic traits with functions without warnings. Any
unimplemented trait items (associated types again) will not be included
in the documentation.

# 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.

---------

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
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
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant