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

Nested generic syntax broken? #1316

Closed
iAmMichaelConnor opened this issue May 8, 2023 · 1 comment · Fixed by #1319
Closed

Nested generic syntax broken? #1316

iAmMichaelConnor opened this issue May 8, 2023 · 1 comment · Fixed by #1319
Labels
bug Something isn't working

Comments

@iAmMichaelConnor
Copy link
Collaborator

iAmMichaelConnor commented May 8, 2023

Aim

Here's a minimal example. I want to write A<B<C>> for some concrete type C, but the compiler complains with error: Unexpected <, expected one of >, ,, ::, binary operator; I.e. it didn't expect to see < twice.

I conjured this example just as a way of being able to justify writing A<B<Field>>.

    struct A<T> {
        b: T,
    }

    impl<T> A<T> {
        fn new(b: T) -> Self {
            A { b }
        }
    }

    struct B<T> {
        c: T,
    }

    impl<T> B<T> {
        fn new(c: T) -> Self {
            B { c }
        }
    }


    fn main (c: Field, d: Field) -> pub A<B<Field>> {
        let mut b = B::new(c);
        let mut a = A::new(b);
        
        let mut ab = a.b;
        ab.c *= d;
        ab
    }
error: Unexpected <, expected one of >, ,, ::, binary operator
   ┌─ /mnt/user-data/mike/packages/yarn-project/noir-contracts/src/contracts/zk_nft_contract/src/main.nr:50:44
   │
50 │     fn main (c: Field, d: Field) -> pub A<B<Field>> {
   │                                            -

Installation method

noirup

Nargo version

nargo 0.4.1 (git version hash: 3d2233d, is dirty: false)

@iAmMichaelConnor iAmMichaelConnor added the bug Something isn't working label May 8, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 8, 2023
@jfecher
Copy link
Contributor

jfecher commented May 8, 2023

Ah, this is caused by the >> being tokenized as a right shift. So the parser sees A lessthan B lessthan Field rightshift rather than two separate greater-than tokens to terminate each generics list.

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 8, 2023
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.

2 participants