-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow a trait to be implemented multiple times for the same str…
…uct (#3292)
- Loading branch information
Showing
6 changed files
with
108 additions
and
71 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
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
7 changes: 7 additions & 0 deletions
7
tooling/nargo_cli/tests/compile_success_empty/trait_generics/Nargo.toml
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,7 @@ | ||
[package] | ||
name = "trait_generics" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = "0.10.5" | ||
|
||
[dependencies] |
27 changes: 27 additions & 0 deletions
27
tooling/nargo_cli/tests/compile_success_empty/trait_generics/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 @@ | ||
|
||
struct Empty<T> {} | ||
|
||
trait Foo { | ||
fn foo(self) -> u32; | ||
} | ||
|
||
impl Foo for Empty<u32> { | ||
fn foo(_self: Self) -> u32 { 32 } | ||
} | ||
|
||
impl Foo for Empty<u64> { | ||
fn foo(_self: Self) -> u32 { 64 } | ||
} | ||
|
||
fn main() { | ||
let x: Empty<u32> = Empty {}; | ||
let y: Empty<u64> = Empty {}; | ||
let z = Empty {}; | ||
|
||
assert(x.foo() == 32); | ||
assert(y.foo() == 64); | ||
|
||
// Types matching multiple impls will currently choose | ||
// the first matching one instead of erroring | ||
assert(z.foo() == 32); | ||
} |