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

Calling trait method from its full path panics #5557

Closed
michaeljklein opened this issue Jul 18, 2024 · 1 comment · Fixed by #5577
Closed

Calling trait method from its full path panics #5557

michaeljklein opened this issue Jul 18, 2024 · 1 comment · Fixed by #5577
Assignees
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to call Add::add function without using a method call:

fn main() {
    let _ = std::ops::Add::add(
        1, 2
    );
}

Expected Behavior

Expected a user error

Bug

The application panicked (crashed).
Message:  assertion `left == right` failed
  left: 1
 right: 0
Location: compiler/noirc_evaluator/src/ssa/opt/inlining.rs:583

To Reproduce

Project Impact

None

Impact Context

No response

Workaround

Yes

Workaround Description

Bisect the program to find the error

Additional Context

No response

Installation Method

None

Nargo Version

nargo version = 0.31.0 noirc version = 0.31.0+45e82a672b9ba7f7326e8d9f8800e2489013e2e8 (git version hash: 45e82a6, is dirty: false)

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Jul 18, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 18, 2024
@jfecher
Copy link
Contributor

jfecher commented Jul 18, 2024

This seems to be related to imports of traits somehow:

use std::cmp::Eq;

fn main() {
    let x: Field = 0 ;
    let _ = Eq::eq(x, x);
}

Works but the following does not:

fn main() {
    let x: Field = 0 ;
    let _ = std::cmp::Eq::eq(x, x);
}

I've confirmed this is still the case when using a locally defined MyEq trait instead of the one from the stdlib.

@jfecher jfecher changed the title Calling trait method as a normal function panics Calling trait method from its full path panics Jul 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Jul 22, 2024
…actly two segments (#5577)

# Description

## Problem

Resolves #5557

## Summary

For something like `Add::add` the logic was checking if `Add` was a
trait, then looking for a method `add` in it. It only worked if the path
had exactly two segments.

I initially thought the fix was simple: also make it work if there are
more segments. However, it got tricky if there's just one segment: we
need to find out the trait associated with the found function. This
wasn't tracked in `FuncMeta` (well, there was a boolean for it but not
the optional `TraitId`) so in this PR this information is now tracked,
and the lookup works in all cases.

## Additional Context

None.

## 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 Jul 22, 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
Projects
Status: Done
3 participants