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

Expected identical type with arithmetic generics #6006

Closed
jfecher opened this issue Sep 11, 2024 · 0 comments · Fixed by #6008
Closed

Expected identical type with arithmetic generics #6006

jfecher opened this issue Sep 11, 2024 · 0 comments · Fixed by #6008
Assignees
Labels
bug Something isn't working

Comments

@jfecher
Copy link
Contributor

jfecher commented Sep 11, 2024

Aim

/// A trait for types that can be decoded from a calldata field array
trait FromCallData<let N: u32, let M: u32> {
    /// Decodes Self by consuming it from the head of calldata, returning the remaining calldata
    fn from_calldata(calldata: [Field; N]) -> (Self, [Field; M]);
}

struct Point { x: Field, y: Field }

impl <let N: u32> FromCallData<N, N - 1> for Field {
    fn from_calldata(calldata: [Field; N]) -> (Self, [Field; (N - 1)]) {
        let slice = calldata.as_slice();
        let (value, slice) = slice.pop_front();
        (value, slice.as_array())
    }
}

impl <let N: u32> FromCallData<N, N - 2> for Point {
    fn from_calldata(calldata: [Field; N]) -> (Self, [Field; (N - 2)]) {
        let (x, calldata) = FromCallData::from_calldata(calldata);
        let (y, calldata) = (1, foo(calldata));//FromCallData::from_calldata(calldata);
        (Self { x, y }, calldata)
    }
}

fn foo<let N: u32>(_a: [Field; N]) -> [Field; N - 1] {
    std::mem::zeroed()
}

fn main() {
    let calldata = [1, 2];
    let _: (Point, _) = FromCallData::from_calldata(calldata);
}

Expected Behavior

The program to type check correctly

Bug

error: expected type (Point, [Field; (N - 2)]), found type (Point, [Field; (N - 2)])
   ┌─ src/main.nr:18:47
   │
18 │     fn from_calldata(calldata: [Field; N]) -> (Self, [Field; (N - 2)]) {
   │                                               ------------------------ expected (Point, [Field; (N - 2)]) because of return type
   ·
21 │         (Self { x, y }, calldata)
   │         ------------------------- (Point, [Field; (N - 2)]) returned here
   │

(The error changes if the foo call is replaced with another from_call_data call)

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher jfecher added the bug Something isn't working label Sep 11, 2024
@jfecher jfecher self-assigned this Sep 11, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 11, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 12, 2024
jfecher added a commit that referenced this issue Sep 12, 2024
…6008)

# Description

## Problem\*

Resolves #6006

## Summary\*

Previously we were failing for constraints like `a + 3 = b + 1` when we
could instead move the constant terms to one side: `a + 2 = b` then
solve with `b := a + 2`.

## 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.
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
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant