-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Verify impls arising from function calls exist (#3472)
- Loading branch information
1 parent
a002e8c
commit c8a4312
Showing
5 changed files
with
81 additions
and
13 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
6 changes: 6 additions & 0 deletions
6
tooling/nargo_cli/tests/compile_failure/no_impl_from_function/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,6 @@ | ||
[package] | ||
name = "no_impl_from_function" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
26 changes: 26 additions & 0 deletions
26
tooling/nargo_cli/tests/compile_failure/no_impl_from_function/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,26 @@ | ||
fn main() { | ||
let array: [Field; 3] = [1, 2, 3]; | ||
assert(foo(array)); | ||
|
||
// Ensure this still works if we have to infer the type of the integer literals | ||
let array = [1, 2, 3]; | ||
assert(foo(array)); | ||
} | ||
|
||
fn foo<T>(x: T) -> bool where T: Eq { | ||
x.eq(x) | ||
} | ||
|
||
trait Eq { | ||
fn eq(self, other: Self) -> bool; | ||
} | ||
|
||
impl<T, N> Eq for [T; N] where T: Eq { | ||
fn eq(self, other: Self) -> bool { | ||
let mut ret = true; | ||
for i in 0 .. self.len() { | ||
ret &= self[i].eq(other[i]); | ||
} | ||
ret | ||
} | ||
} |