-
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.
Support pattern contracts in match statement (#1823)
* Apply pattern contracts in match expressions Match expressions have been extended to accept the full range of patterns (that was reserved to destructuring before). Patterns allow, in particular, to annotate fields with metadata, such as contract annotations or default values. Those were, until now, simply ignored by the new match expressions. This commit modifies the pattern compilation scheme to handle contracts and default values properly. * Add tests for contracts in match patterns * Fix clippy warning * Renaming a couple test files
- Loading branch information
Showing
8 changed files
with
193 additions
and
50 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
7 changes: 7 additions & 0 deletions
7
core/tests/integration/inputs/pattern-matching/contract_blame.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::BlameError' | ||
{foo.bar = 5} |> match { | ||
{foo={bar | String}} => bar, | ||
} |
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,9 @@ | ||
# test.type = 'pass' | ||
|
||
let {check, ..} = import "../lib/assert.ncl" in | ||
|
||
[ | ||
{foo = {}} |> match { {foo = {bar ? 5}} => true}, | ||
{foo = {}} |> match { {foo = {bar | String }} => false, {foo} => true}, | ||
] | ||
|> check |
7 changes: 7 additions & 0 deletions
7
core/tests/integration/inputs/pattern-matching/default_value_array_merge_conflict.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::BlameError' | ||
{foo.bar | default = []} |> match { | ||
{foo={bar ? [1]}} => bar, | ||
} |
7 changes: 7 additions & 0 deletions
7
core/tests/integration/inputs/pattern-matching/default_value_merge_conflict.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::MergeIncompatibleArgs' | ||
{foo.bar | default = 5} |> match { | ||
{foo={bar ? 6}} => bar, | ||
} |