forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move `std::assert::require` to `std::revert` * Fix comment * Remove unused use Co-authored-by: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
02b7e94
commit aa5dc0d
Showing
6 changed files
with
23 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,14 @@ | ||
library assert; | ||
|
||
use ::logging::log; | ||
use ::revert::revert; | ||
|
||
const FAILED_REQUIRE_SIGNAL = 42; | ||
|
||
/// Assert that a value is true | ||
pub fn assert(a: bool) { | ||
if !a { | ||
/// Asserts that the given `condition` will always be `true` during runtime. | ||
/// To check for conditions that may not be `true`, use `std::revert::require` instead. | ||
/// See: https://en.wikipedia.org/wiki/Assertion_(software_development)#Comparison_with_error_handling | ||
pub fn assert(condition: bool) { | ||
if !condition { | ||
revert(0); | ||
} else { | ||
() | ||
} | ||
} | ||
|
||
/// A wrapper for `assert` that allows logging a custom value `v` if condition `c` is not true. | ||
pub fn require<T>(c: bool, v: T) { | ||
if !c { | ||
log(v); | ||
revert(FAILED_REQUIRE_SIGNAL) | ||
} else { | ||
() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
library std; | ||
|
||
dep intrinsics; | ||
dep revert; | ||
dep logging; | ||
dep revert; | ||
dep assert; | ||
dep option; | ||
dep result; | ||
|
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
2 changes: 1 addition & 1 deletion
2
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/require/src/main.sw
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