-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter checks and reporting errors
- Loading branch information
1 parent
d3c4f54
commit 3cf1109
Showing
5 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
crates/nargo_cli/tests/compile_tests_data/fail/trait_wrong_method_name.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,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); | ||
} |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_tests_data/fail/trait_wrong_method_return_type.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,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); | ||
} |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_tests_data/fail/trait_wrong_parameter.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,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); | ||
} |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/compile_tests_data/fail/trait_wrong_parameters_count.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,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); | ||
} |
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