-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply generic arguments from trait constraints before instantiat…
…ing identifiers (#4121) # Description ## Problem\* Resolves #4088 ## Summary\* We were calling `instantiate` on identifiers before applying any trait constraints. So if we have a constraint like `Foo<Field>` (referring to the trait `trait Foo<T> { ... }`, and an identifier `foo : forall T. fn(T)`, we need to apply the `T = Field` constraint before instantiating `foo` to replace `T` with a fresh type variable. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** 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. --------- Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
- Loading branch information
Showing
5 changed files
with
101 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
name = "regression_4088" | ||
type = "bin" | ||
authors = [""] | ||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[note] | ||
value = 0 |
27 changes: 27 additions & 0 deletions
27
test_programs/execution_success/regression_4088/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
trait Serialize<N> { | ||
fn serialize(self) -> [Field; N]; | ||
} | ||
|
||
struct ValueNote { | ||
value: Field, | ||
} | ||
|
||
impl Serialize<1> for ValueNote { | ||
fn serialize(self) -> [Field; 1] { | ||
[self.value] | ||
} | ||
} | ||
|
||
fn check<N>(serialized_note: [Field; N]) { | ||
assert(serialized_note[0] == 0); | ||
} | ||
|
||
fn oopsie<Note, N>(note: Note) where Note: Serialize<N> { | ||
let serialized_note = Note::serialize(note); | ||
|
||
check(serialized_note) | ||
} | ||
|
||
fn main(mut note: ValueNote) { | ||
oopsie(note); | ||
} |