-
Notifications
You must be signed in to change notification settings - Fork 387
feat: Basic implementation of traits #2368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jfecher
merged 31 commits into
noir-lang:master
from
metacraft-labs:yordan/resolve_traits_initial
Aug 30, 2023
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
49984f7
Maybe it's better this way
ymadzhunkov 4a007aa
Collect traits from AST to def_map
ymadzhunkov 29094f0
Collect trait implementations in def collector
ymadzhunkov 5d00169
Resolve traits
ymadzhunkov a6615f2
Separate collected trait implementations
ymadzhunkov 568119f
fix(testsuite): converted traits tests to proper nargo packages
nickysn 788ef07
fix(testsuite): added Prover.toml files to the traits compile_failure…
nickysn 5032e7d
fix(testsuite): Move trait test into correct place so it can run auto…
ymadzhunkov ed1790a
Rename trait_not_exists -> trait_not_in_scope
ymadzhunkov 1c63592
Resolve some of PR comments
ymadzhunkov 4f5d1df
better naming as requsted in PR
ymadzhunkov a7f7188
Remove empty else and rename noir_function -> impl_method
ymadzhunkov e46c437
Check for matching of trait implementation method, when unspecified r…
ymadzhunkov 44d9ee4
Apply cargo clippy suggestions
ymadzhunkov b41bab5
Delete duplicated test
ymadzhunkov 7046cf1
Partial trait resolution
ymadzhunkov 3f98928
Extract comparison of return type into stuct assosiated method
ymadzhunkov 68f0a15
Add test of a trait with default implemetation that is used
ymadzhunkov d5caec4
Allow usage of default trait implementation
ymadzhunkov 295f057
RP remark: fix typo
ymadzhunkov 36096d4
Maybem it's better this way
ymadzhunkov 87ed6e2
Fix clippy warnings
ymadzhunkov 28edd77
Add test of override ot Trait default method
ymadzhunkov d2873ef
Try to fix 'nix flake check -L'
ymadzhunkov dd88b96
Try to fix CI dependency failed build
ymadzhunkov 961550b
An other try
ymadzhunkov bbe62b6
Update crates/noirc_frontend/src/ast/mod.rs
yordanmadzhunkov 28a3aaa
Update crates/noirc_frontend/src/hir/def_collector/dc_crate.rs
yordanmadzhunkov 2ef48e2
Build fix and cargo fmt
ymadzhunkov 05b5208
Fix build after rebase of master
ymadzhunkov 43ec02d
Fix trait tests
ymadzhunkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/dup_trait_declaration/Nargo.toml
This file contains hidden or 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 = "dup_trait_declaration" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/dup_trait_declaration/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
26 changes: 26 additions & 0 deletions
26
crates/nargo_cli/tests/compile_failure/dup_trait_declaration/src/main.nr
This file contains hidden or 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,26 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field,y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| // Duplicate trait declarations should not compile | ||
| trait Default { | ||
| fn default(x: Field) -> Self; | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/dup_trait_implementation/Nargo.toml
This file contains hidden or 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 = "dup_trait_implementation" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/dup_trait_implementation/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
30 changes: 30 additions & 0 deletions
30
crates/nargo_cli/tests/compile_failure/dup_trait_implementation/src/main.nr
This file contains hidden or 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,30 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| // Duplicate trait implementations should not compile | ||
| impl Default for Foo { | ||
| fn default(x: Field,y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| // Duplicate trait implementations should not compile | ||
| impl Default for Foo { | ||
| fn default(x: Field, y: Field) -> Self { | ||
| Self { bar: y, array: [y,x] } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/impl_struct_not_trait/Nargo.toml
This file contains hidden or 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 = "impl_struct_not_trait" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/impl_struct_not_trait/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
23 changes: 23 additions & 0 deletions
23
crates/nargo_cli/tests/compile_failure/impl_struct_not_trait/src/main.nr
This file contains hidden or 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,23 @@ | ||
| use dep::std; | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| struct Default { | ||
| x: Field, | ||
| z: Field, | ||
| } | ||
|
|
||
| // Default is struct not a trait | ||
| impl Default for Foo { | ||
| fn default(x: Field, y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_missing_implementation/Nargo.toml
This file contains hidden or 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 = "traits" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.1" | ||
|
|
||
| [dependencies] |
24 changes: 24 additions & 0 deletions
24
crates/nargo_cli/tests/compile_failure/trait_missing_implementation/src/main.nr
This file contains hidden or 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,24 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
|
|
||
| fn method2(x: Field) -> Field; | ||
|
|
||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field,y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field) { | ||
| let first = Foo::method2(x); | ||
| assert(first == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_not_in_scope/Nargo.toml
This file contains hidden or 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_not_in_scope" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_not_in_scope/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
18 changes: 18 additions & 0 deletions
18
crates/nargo_cli/tests/compile_failure/trait_not_in_scope/src/main.nr
This file contains hidden or 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,18 @@ | ||
| use dep::std; | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| // Default trait does not exist | ||
| impl Default for Foo { | ||
| fn default(x: Field, y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_method_name/Nargo.toml
This file contains hidden or 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_wrong_method_name" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_wrong_method_name/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
22 changes: 22 additions & 0 deletions
22
crates/nargo_cli/tests/compile_failure/trait_wrong_method_name/src/main.nr
This file contains hidden or 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,22 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| // wrong trait name method should not compile | ||
| impl Default for Foo { | ||
| fn default_wrong_name(x: Field, y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default_wrong_name(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_method_return_type/Nargo.toml
This file contains hidden or 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_wrong_method_return_type" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_wrong_method_return_type/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_failure/trait_wrong_method_return_type/src/main.nr
This file contains hidden or 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,21 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field, y: Field) -> Field { | ||
| x | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter/Nargo.toml
This file contains hidden or 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_wrong_parameter" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter/src/main.nr
This file contains hidden or 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,21 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field, y: Foo) -> Self { | ||
| Self { bar: x, array: [x, y.bar] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter_type/Nargo.toml
This file contains hidden or 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_wrong_method_return_type" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter_type/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_parameter_type/src/main.nr
This file contains hidden or 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 @@ | ||
| trait Default { | ||
| fn default(x: Field, y: NotAType) -> Field; | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| assert(y == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/compile_failure/trait_wrong_parameters_count/Nargo.toml
This file contains hidden or 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_wrong_parameters_count" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.9.0" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/compile_failure/trait_wrong_parameters_count/Prover.toml
This file contains hidden or 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 @@ | ||
| x = 1 | ||
| y = 2 |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_failure/trait_wrong_parameters_count/src/main.nr
This file contains hidden or 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,21 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field) -> Self { | ||
| Self { bar: x, array: [x, x] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field, y: Field) { | ||
| let first = Foo::default(x,y); | ||
| assert(first.bar == x); | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/execution_success/trait_default_implementation/Nargo.toml
This file contains hidden or 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_default_implementation" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.1" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/execution_success/trait_default_implementation/Prover.toml
This file contains hidden or 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 @@ | ||
| x = "5" | ||
| y = "1" |
26 changes: 26 additions & 0 deletions
26
crates/nargo_cli/tests/execution_success/trait_default_implementation/src/main.nr
This file contains hidden or 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,26 @@ | ||
| use dep::std; | ||
|
|
||
| trait Default { | ||
| fn default(x: Field, y: Field) -> Self; | ||
|
|
||
| fn method2(x: Field) -> Field { | ||
| x | ||
| } | ||
|
|
||
| } | ||
|
|
||
| struct Foo { | ||
| bar: Field, | ||
| array: [Field; 2], | ||
| } | ||
|
|
||
| impl Default for Foo { | ||
| fn default(x: Field,y: Field) -> Self { | ||
| Self { bar: x, array: [x,y] } | ||
| } | ||
| } | ||
|
|
||
| fn main(x: Field) { | ||
| let first = Foo::method2(x); | ||
| assert(first == x); | ||
| } |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/execution_success/trait_override_implementation/Nargo.toml
This file contains hidden or 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_override_implementation" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = "0.1" | ||
|
|
||
| [dependencies] |
2 changes: 2 additions & 0 deletions
2
crates/nargo_cli/tests/execution_success/trait_override_implementation/Prover.toml
This file contains hidden or 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 @@ | ||
| x = "5" | ||
| y = "1" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.