-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add compile-time assertions on generic arguments of stdlib fun…
…ctions (#6981) Co-authored-by: Tom French <[email protected]>
- Loading branch information
1 parent
c8d5ce5
commit dce2c7d
Showing
15 changed files
with
210 additions
and
14 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
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
6 changes: 6 additions & 0 deletions
6
test_programs/compile_failure/comptime_static_assert_failure/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 = "comptime_static_assert_failure" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
13 changes: 13 additions & 0 deletions
13
test_programs/compile_failure/comptime_static_assert_failure/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,13 @@ | ||
use std::static_assert; | ||
|
||
comptime fn foo(x: Field) -> bool { | ||
static_assert(x == 4, "x != 4"); | ||
x == 4 | ||
} | ||
|
||
fn main() { | ||
comptime { | ||
static_assert(foo(3), "expected message"); | ||
} | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
test_programs/compile_success_empty/comptime_static_assert/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 = "comptime_static_assert" | ||
type = "bin" | ||
authors = [""] | ||
|
||
[dependencies] |
19 changes: 19 additions & 0 deletions
19
test_programs/compile_success_empty/comptime_static_assert/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,19 @@ | ||
use std::static_assert; | ||
|
||
comptime fn foo(x: Field) -> bool { | ||
static_assert(x == 4, "x != 4"); | ||
x == 4 | ||
} | ||
|
||
global C: bool = { | ||
let out = foo(2 + 2); | ||
static_assert(out, "foo did not pass in C"); | ||
out | ||
}; | ||
|
||
fn main() { | ||
comptime { | ||
static_assert(foo(4), "foo did not pass in main"); | ||
static_assert(C, "C did not pass") | ||
} | ||
} |
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
Oops, something went wrong.