-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Variables from trait constraints being permanently bound over wh…
…en used within a trait impl (#4450) # Description ## Problem\* Resolves #4436 ## Summary\* This issue stemmed from calling another trait method within an impl for the trait. The trait method required a trait constraint of the same trait to be valid and was using the trait with its original type variables. These would later be bound over when an impl was searched for for this trait. I've added a somewhat hacky solution of avoiding inserting `t = t` bindings from the trait constraint when checking identifiers. Avoiding inserting this binding means `t` in this case will later be instantiated to a fresh type variable later on in the `instantiate_with_bindings` call. ## 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.
- Loading branch information
Showing
4 changed files
with
41 additions
and
2 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_4436" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.22.0" |
31 changes: 31 additions & 0 deletions
31
test_programs/execution_success/regression_4436/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,31 @@ | ||
trait LibTrait<N> { | ||
fn broadcast(); | ||
fn get_constant() -> Field; | ||
} | ||
|
||
global STRUCT_A_LEN: Field = 3; | ||
global STRUCT_B_LEN: Field = 5; | ||
|
||
struct StructA; | ||
struct StructB; | ||
|
||
impl LibTrait<u32> for StructA { | ||
fn broadcast() { | ||
Self::get_constant(); | ||
} | ||
|
||
fn get_constant() -> Field { | ||
1 | ||
} | ||
} | ||
impl LibTrait<u64> for StructB { | ||
fn broadcast() { | ||
Self::get_constant(); | ||
} | ||
|
||
fn get_constant() -> Field { | ||
1 | ||
} | ||
} | ||
|
||
fn main() {} |