-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(traits): allow multiple traits to share the same associated func…
…tion name and to be implemented for the same type (#3126)
- Loading branch information
Showing
6 changed files
with
163 additions
and
34 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
7 changes: 7 additions & 0 deletions
7
tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/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_associated_member_names_clashes" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = "0.16.0" | ||
|
||
[dependencies] |
Empty file.
36 changes: 36 additions & 0 deletions
36
tooling/nargo_cli/tests/execution_success/trait_associated_member_names_clashes/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,36 @@ | ||
trait Trait1 { | ||
fn tralala() -> Field; | ||
} | ||
|
||
trait Trait2 { | ||
fn tralala() -> Field; | ||
} | ||
|
||
struct Struct1 { | ||
} | ||
|
||
impl Struct1 { | ||
fn tralala() -> Field { | ||
123456 | ||
} | ||
} | ||
|
||
impl Trait1 for Struct1 { | ||
fn tralala() -> Field { | ||
111111 | ||
} | ||
} | ||
|
||
impl Trait2 for Struct1 { | ||
fn tralala() -> Field { | ||
222222 | ||
} | ||
} | ||
|
||
fn main() { | ||
// the struct impl takes priority over trait methods | ||
assert(Struct1::tralala() == 123456); | ||
// TODO: uncomment these, once we support the <Type as Trait>:: syntax | ||
//assert(<Struct1 as Trait1>::tralala() == 111111); | ||
//assert(<Struct1 as Trait2>::tralala() == 222222); | ||
} |