Skip to content

fix: Make trait functions generic over Self#3702

Merged
kevaundray merged 1 commit intojf/fix-3089from
jf/fix-traits-bug
Dec 7, 2023
Merged

fix: Make trait functions generic over Self#3702
kevaundray merged 1 commit intojf/fix-3089from
jf/fix-traits-bug

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
@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.

2 participants