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

fix: Make trait functions generic over Self #3702

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Dec 6, 2023

Description

Problem & Summary

Checking a trait function's type previously was very ad-hoc. When a TraitMethodReference was found, it'd manually create a function type from the trait function's definition and instantiate it - even though instantiating a Type::Function does nothing.

I've changed the TraitFunction struct to add a Type field for the whole function type, which includes generics. The type now should usually be a Type::Forall. In addition, I've added the trait's Self type to the list of generics in the Type::Forall.

This fixes the issue where the Self type would be bound after certain function calls which would affect callsites but not a function body leading to a type mismatch between function return type and a call's return type. This is the issue we were encountering after adding traits to noir-protocol-circuits.

Additional Information

No tests are provided since I was unable to make a minimal repro from the thousands of lines of noir-protocol-circuits unfortunately. I'll keep experimenting while this PR is up.

I'm also merging into jf/fix-3089 since this was somewhat accidentally built on top of it. The two changes are otherwise unrelated.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [Exceptional Case] Documentation to be submitted in a separate PR.

PR Checklist*

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

@kevaundray kevaundray merged commit 20bd680 into jf/fix-3089 Dec 7, 2023
33 checks passed
@kevaundray kevaundray deleted the jf/fix-traits-bug branch December 7, 2023 12:43
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.

None yet

2 participants