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

feat: Implement parsing of traits #1886

Merged
merged 5 commits into from
Jul 12, 2023
Merged

feat: Implement parsing of traits #1886

merged 5 commits into from
Jul 12, 2023

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Jul 7, 2023

Description

Problem*

Working towards #527

Summary*

Adds support for parsing:

  • trait definitions
  • trait implementations
  • trait constraint expressions on functions

Since traits as a whole are unimplemented, I added a parsing error to alert users that traits are still unimplemented. This will allow use to better split traits into smaller PRs like this one rather than implementing them all at once.

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher
Copy link
Contributor Author

jfecher commented Jul 7, 2023

Here's an example that now parses:

trait Foo<A, B> {
    type Element;

    fn iter<C>(&mut self, stop: bool) -> Field 
        where C: Foo<C, Element>;
}

impl<A> Foo<A, Field> for u32 where A: Bar {
    type Element = u8;

    fn iter<C>(&mut self, stop: bool) -> Field 
        where C: Foo<C, u8>
    {
        if stop { 0 } else { 1 }
    }
}

fn bar<T>(x: T) -> T where T: Bar {
    x.bar()
}

kevaundray
kevaundray previously approved these changes Jul 10, 2023
@jfecher jfecher requested a review from kevaundray July 12, 2023 18:14
@kevaundray kevaundray added this pull request to the merge queue Jul 12, 2023
Merged via the queue into master with commit 3ba1e72 Jul 12, 2023
@kevaundray kevaundray deleted the jf/trait-syntax branch July 12, 2023 19:17
@nickysn nickysn mentioned this pull request Sep 5, 2023
46 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants