-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow some function equality comparison (#1978)
* Allow some function equality comparison Relax the initial restriction on comparing functions, which is that comparing a function to anything else error out. In practice comparing a function to a value of some other type isn't a problem, and can be useful to allow patterns like `if x != null then ... else ...` without having first to check if `x` is a function, because that would fail at runtime. Instead, we only forbid comparison between two function-like values (functions, match expressions and custom contracts) and between two opaque foreign values. * Fix typo in code comment * Additional tests for relaxed function comparison Check the relaxed function comparison, which errors out when trying to compare two functions, but can compare a function to a value of a different type (by always returning false). Tests that functions can't be compared were already there, but this commit adds tests that function can be compared to other values.
- Loading branch information
Showing
8 changed files
with
89 additions
and
48 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
7 changes: 7 additions & 0 deletions
7
core/tests/integration/inputs/contracts/equating_fn_match.ncl
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,7 @@ | ||
# test.type = 'error' | ||
# | ||
# [test.metadata] | ||
# error = 'EvalError::IncomparableValues' | ||
let g = fun x => x + 1 in | ||
let h = match { 0 => 0 } in | ||
g == h |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ion/inputs/contracts/equating_fns_rhs.ncl → ...n/inputs/contracts/equating_functions.ncl
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,6 +1,6 @@ | ||
# test.type = 'error' | ||
# | ||
# [test.metadata] | ||
# error = 'EvalError::EqError' | ||
# error = 'EvalError::IncomparableValues' | ||
let g = fun x => x + 1 in | ||
"a" == g | ||
g == g |
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